SAGA API v9.10
Loading...
Searching...
No Matches
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//---------------------------------------------------------
77
78//---------------------------------------------------------
79long 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//---------------------------------------------------------
85bool 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//---------------------------------------------------------
144CSG_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; m_nColors = 0;
175
176 Create();
177}
178
179//---------------------------------------------------------
181{
182 m_Colors = NULL; m_nColors = 0;
183
184 Create(Colors);
185}
186
187//---------------------------------------------------------
188CSG_Colors::CSG_Colors(int nColors, int Palette, bool bRevert)
189{
190 m_Colors = NULL; m_nColors = 0;
191
192 Create(nColors, Palette, bRevert);
193}
194
195//---------------------------------------------------------
196CSG_Colors::CSG_Colors(const CSG_String &Palette, int nColors, bool bRevert)
197{
198 m_Colors = NULL; m_nColors = 0;
199
200 Create(Palette, nColors, bRevert);
201}
202
203//---------------------------------------------------------
205{
206 Destroy();
207}
208
209
211// //
213
214//---------------------------------------------------------
216{
217 return( Create(11) );
218}
219
220//---------------------------------------------------------
222{
223 if( Colors.m_nColors > 0 )
224 {
225 m_nColors = Colors.m_nColors;
226 m_Colors = (long *)SG_Realloc(m_Colors, m_nColors * sizeof(long));
227
228 memcpy(m_Colors, Colors.m_Colors, m_nColors * sizeof(long));
229
230 return( true );
231 }
232
233 return( false );
234}
235
236//---------------------------------------------------------
237bool CSG_Colors::Create(int nColors, int Palette, bool bRevert)
238{
239 return( Set_Palette(Palette, bRevert, nColors) || Set_Palette(SG_COLORS_DEFAULT, bRevert, nColors) );
240}
241
242//---------------------------------------------------------
243bool CSG_Colors::Create(const CSG_String &Palette, int nColors, bool bRevert)
244{
245 return( Set_Palette(Palette, bRevert, nColors) || Set_Palette(SG_COLORS_DEFAULT, bRevert, nColors) );
246}
247
248//---------------------------------------------------------
250{
251 if( m_nColors > 0 )
252 {
253 SG_Free(m_Colors);
254
255 m_Colors = NULL; m_nColors = 0;
256 }
257}
258
259
261// //
263
264//---------------------------------------------------------
265bool CSG_Colors::Set_Count(int nColors)
266{
267 if( nColors == m_nColors )
268 {
269 return( true );
270 }
271
272 if( nColors < 1 )
273 {
274 return( false );
275 }
276
277 if( m_nColors == 0 )
278 {
279 return( Set_Default(nColors) );
280 }
281
282 //-----------------------------------------------------
283 CSG_Colors Colors(*this);
284
285 m_nColors = nColors;
286 m_Colors = (long *)SG_Realloc(m_Colors, m_nColors * sizeof(long));
287
288 double dStep = Get_Count() > 1 ? (Colors.Get_Count() - 1.0) / (Get_Count() - 1.0) : 0.0;
289
290 for(int i=0; i<Get_Count(); i++)
291 {
292 if( Get_Count() < Colors.Get_Count() )
293 {
294 m_Colors[i] = Colors[(int)(i * dStep)];
295 }
296 else // if( Get_Count() > Colors.Get_Count() )
297 {
298 m_Colors[i] = Colors.Get_Interpolated(i * dStep);
299 }
300 }
301
302 //-----------------------------------------------------
303 return( true );
304}
305
306
308// //
310
311//---------------------------------------------------------
312bool CSG_Colors::Set_Color(int Index, long Color)
313{
314 if( Index >= 0 && Index < m_nColors )
315 {
316 m_Colors[Index] = Color;
317
318 return( true );
319 }
320
321 return( false );
322}
323
324//---------------------------------------------------------
325bool CSG_Colors::Set_Color(int Index, int Red, int Green, int Blue)
326{
327 return( Set_Color(Index, SG_GET_RGB(Red, Green, Blue)) );
328}
329
330//---------------------------------------------------------
331bool CSG_Colors::Set_Red(int Index, int Value)
332{
333 return( Set_Color(Index, Value , Get_Green(Index) , Get_Blue(Index)) );
334}
335
336//---------------------------------------------------------
337bool CSG_Colors::Set_Green(int Index, int Value)
338{
339 return( Set_Color(Index, Get_Red(Index) , Value , Get_Blue(Index)) );
340}
341
342//---------------------------------------------------------
343bool CSG_Colors::Set_Blue(int Index, int Value)
344{
345 return( Set_Color(Index, Get_Red(Index) , Get_Green(Index) , Value) );
346}
347
348//---------------------------------------------------------
349bool CSG_Colors::Set_Brightness(int Index, int Value)
350{
351 double r, g, b, ds;
352
353 //-----------------------------------------------------
354 if( Value < 0 )
355 {
356 Value = 0;
357 }
358 else if( Value > 255 )
359 {
360 Value = 255;
361 }
362
363 //-----------------------------------------------------
364 r = Get_Red (Index);
365 g = Get_Green(Index);
366 b = Get_Blue (Index);
367 ds = (r + g + b) / 3.0;
368
369 if( ds > 0.0 )
370 {
371 ds = Value / ds;
372 r *= ds;
373 g *= ds;
374 b *= ds;
375
376 _Set_Brightness(r, g, b);
377 }
378 else
379 {
380 r = g = b = Value / 3.0;
381 }
382
383 return( Set_Color(Index, (int)r, (int)g, (int)b) );
384}
385
386//---------------------------------------------------------
387void CSG_Colors::_Set_Brightness(double &a, double &b, double &c, int Pass)
388{
389 if( a > 255 )
390 {
391 int addSum;
392
393 addSum = (int)((a - 255) / 2.0);
394 a = 255;
395
396 b += addSum;
397 c += addSum;
398
399 if( b > 255 )
400 {
401 addSum = (int)(b - 255);
402 b = 255;
403
404 c += addSum;
405
406 if( c > 255 )
407 {
408 c = 255;
409 }
410 }
411 else if( c > 255 )
412 {
413 addSum = (int)(c - 255);
414 c = 255;
415
416 b += addSum;
417
418 if( b > 255 )
419 {
420 b = 255;
421 }
422 }
423 }
424 else if( Pass < 2 )
425 {
426 _Set_Brightness(b, c, a, Pass + 1);
427 }
428}
429
430
432// //
434
435//---------------------------------------------------------
437{
438 return( SG_COLORS_COUNT );
439}
440
441//---------------------------------------------------------
443{
444 #define MAKE_NAME(name) (bWithIndex ? CSG_String::Format("[%d] %s", Index, name) : CSG_String(name))
445
446 switch( Index )
447 {
448 case SG_COLORS_DEFAULT : return( MAKE_NAME(_TL("blue-green-red" )) );
449 case SG_COLORS_DEFAULT_BRIGHT : return( MAKE_NAME(_TL("blue-green-red" )) );
450 case SG_COLORS_RAINBOW : return( MAKE_NAME(_TL("rainbow" )) );
451 case SG_COLORS_RAINBOW_2 : return( MAKE_NAME(_TL("rainbow" )) );
452
453 case SG_COLORS_BLACK_WHITE : return( MAKE_NAME(_TL("greyscale" )) );
454 case SG_COLORS_BLACK_RED : return( MAKE_NAME(_TL("black-red" )) );
455 case SG_COLORS_BLACK_GREEN : return( MAKE_NAME(_TL("black-green" )) );
456 case SG_COLORS_BLACK_BLUE : return( MAKE_NAME(_TL("black-blue" )) );
457
458 case SG_COLORS_WHITE_RED : return( MAKE_NAME(_TL("white-red" )) );
459 case SG_COLORS_WHITE_GREEN : return( MAKE_NAME(_TL("white-green" )) );
460 case SG_COLORS_WHITE_BLUE : return( MAKE_NAME(_TL("white-blue" )) );
461
462 case SG_COLORS_CYAN_WHITE : return( MAKE_NAME(_TL("cyan-white" )) );
463 case SG_COLORS_MAGENTA_WHITE : return( MAKE_NAME(_TL("magenta-white" )) );
464 case SG_COLORS_YELLOW_WHITE : return( MAKE_NAME(_TL("yellow-white" )) );
465
466 case SG_COLORS_YELLOW_RED : return( MAKE_NAME(_TL("yellow-red" )) );
467 case SG_COLORS_YELLOW_GREEN : return( MAKE_NAME(_TL("yellow-green" )) );
468 case SG_COLORS_YELLOW_BLUE : return( MAKE_NAME(_TL("yellow-blue" )) );
469
470 case SG_COLORS_BLUE_RED : return( MAKE_NAME(_TL("blue-red" )) );
471 case SG_COLORS_GREEN_RED : return( MAKE_NAME(_TL("green-red" )) );
472 case SG_COLORS_GREEN_BLUE : return( MAKE_NAME(_TL("green-blue" )) );
473
474 case SG_COLORS_BLUE_WHITE_RED : return( MAKE_NAME(_TL("blue-white-red" )) );
475 case SG_COLORS_GREEN_WHITE_RED : return( MAKE_NAME(_TL("green-white-red" )) );
476 case SG_COLORS_GREEN_WHITE_BLUE : return( MAKE_NAME(_TL("green-white-blue" )) );
477
478 case SG_COLORS_BLUE_GREY_RED : return( MAKE_NAME(_TL("blue-grey-red" )) );
479 case SG_COLORS_RED_GREY_BLUE : return( MAKE_NAME(_TL("red-grey-blue" )) );
480 case SG_COLORS_GREEN_GREY_RED : return( MAKE_NAME(_TL("green-grey-red" )) );
481 case SG_COLORS_RED_GREY_GREEN : return( MAKE_NAME(_TL("red-grey-green" )) );
482 case SG_COLORS_GREEN_GREY_BLUE : return( MAKE_NAME(_TL("green-grey-blue" )) );
483
484 case SG_COLORS_BLUE_YELLOW_RED : return( MAKE_NAME(_TL("blue-yellow-red" )) );
485 case SG_COLORS_GREEN_YELLOW_RED : return( MAKE_NAME(_TL("green-yellow-red" )) );
486 case SG_COLORS_RED_YELLOW_GREEN : return( MAKE_NAME(_TL("red-yellow-green" )) );
487 case SG_COLORS_GREEN_YELLOW_BLUE: return( MAKE_NAME(_TL("green-yellow-blue")) );
488
489 case SG_COLORS_RED_GREEN_BLUE : return( MAKE_NAME(_TL("red-green-blue" )) );
490 case SG_COLORS_RED_BLUE_GREEN : return( MAKE_NAME(_TL("red-blue-green" )) );
491 case SG_COLORS_GREEN_RED_BLUE : return( MAKE_NAME(_TL("green-red-blue" )) );
492 case SG_COLORS_NEON : return( MAKE_NAME(_TL("neon" )) );
493
494 case SG_COLORS_TOPOGRAPHY : return( MAKE_NAME(_TL("topography" )) );
495 case SG_COLORS_TOPOGRAPHY_2 : return( MAKE_NAME(_TL("topography" )) );
496 case SG_COLORS_TOPOGRAPHY_3 : return( MAKE_NAME(_TL("topography" )) );
497 case SG_COLORS_TOPOGRAPHY_4 : return( MAKE_NAME(_TL("topography" )) );
498
499 case SG_COLORS_ASPECT_1 : return( MAKE_NAME(_TL("aspect" )) );
500 case SG_COLORS_ASPECT_2 : return( MAKE_NAME(_TL("aspect" )) );
501 case SG_COLORS_ASPECT_3 : return( MAKE_NAME(_TL("aspect" )) );
502
503 case SG_COLORS_THERMAL_1 : return( MAKE_NAME(_TL("thermal" )) );
504 case SG_COLORS_THERMAL_2 : return( MAKE_NAME(_TL("thermal" )) );
505
506 case SG_COLORS_PRECIPITATION_1 : return( MAKE_NAME(_TL("precipitation" )) );
507 case SG_COLORS_PRECIPITATION_2 : return( MAKE_NAME(_TL("precipitation" )) );
508 case SG_COLORS_PRECIPITATION_3 : return( MAKE_NAME(_TL("precipitation" )) );
509 case SG_COLORS_PRECIPITATION_4 : return( MAKE_NAME(_TL("precipitation" )) );
510 case SG_COLORS_PRECIPITATION_5 : return( MAKE_NAME(_TL("precipitation" )) );
511
512 case SG_COLORS_VEGETATION : return( MAKE_NAME(_TL("vegetation" )) );
513
514 case SG_COLORS_SPECTRUM_1 : return( MAKE_NAME(_TL("spectrum" )) );
515 case SG_COLORS_SPECTRUM_2 : return( MAKE_NAME(_TL("spectrum" )) );
516 case SG_COLORS_SPECTRUM_3 : return( MAKE_NAME(_TL("spectrum" )) );
517
518 default : return( _TL("") );
519 }
520}
521
522//---------------------------------------------------------
523bool CSG_Colors::Set_Predefined(int Index, bool bRevert, int nColors)
524{
525 switch( Index )
526 {
528 Set_Default(nColors < 17 ? 17 : nColors);
529 break;
530
532 Set_Default(nColors < 17 ? 17 : nColors);
533 Set_Ramp_Brighness(127, 127);
534 break;
535
537 Set_Count(8);
538 Set_Color(0, SG_GET_RGB( 64, 0, 127));
539 Set_Color(1, SG_GET_RGB( 0, 0, 255));
540 Set_Color(2, SG_GET_RGB( 0, 255, 255));
541 Set_Color(3, SG_GET_RGB( 0, 191, 0));
542 Set_Color(4, SG_GET_RGB(255, 255, 0));
543 Set_Color(5, SG_GET_RGB(255, 127, 0));
544 Set_Color(6, SG_GET_RGB(255, 0, 0));
545 Set_Color(7, SG_GET_RGB(127, 0, 0));
546 break;
547
549 Set_Count(4);
550 Set_Color(0, SG_GET_RGB( 0, 0, 255));
551 Set_Color(1, SG_GET_RGB( 0, 255, 0));
552 Set_Color(2, SG_GET_RGB(255, 255, 0));
553 Set_Color(3, SG_GET_RGB(255, 0, 0));
554 break;
555
556 //-----------------------------------------------------
558 Set_Count(2);
559 Set_Ramp(SG_GET_RGB( 0, 0, 0), SG_GET_RGB(255, 255, 255));
560 break;
561
563 Set_Count(2);
564 Set_Ramp(SG_GET_RGB( 0, 0, 0), SG_GET_RGB(255, 0, 0));
565 break;
566
568 Set_Count(2);
569 Set_Ramp(SG_GET_RGB( 0, 0, 0), SG_GET_RGB( 0, 255, 0));
570 break;
571
573 Set_Count(2);
574 Set_Ramp(SG_GET_RGB( 0, 0, 0), SG_GET_RGB( 0, 0, 255));
575 break;
576
577 //-----------------------------------------------------
579 Set_Count(3);
580 Set_Color(0, SG_GET_RGB(255, 255, 255));
581 Set_Color(1, SG_GET_RGB(255, 127, 0));
582 Set_Color(2, SG_GET_RGB(159, 0, 0));
583 break;
584
586 Set_Count(2);
587 Set_Ramp(SG_GET_RGB(255, 255, 255), SG_GET_RGB( 0, 127, 0));
588 break;
589
591 Set_Count(3);
592 Set_Color(0, SG_GET_RGB(255, 255, 255));
593 Set_Color(1, SG_GET_RGB( 0, 127, 255));
594 Set_Color(2, SG_GET_RGB( 0, 0, 159));
595 break;
596
597 //-----------------------------------------------------
599 Set_Count(2);
600 Set_Color(0, SG_GET_RGB( 0, 255, 255));
601 Set_Color(1, SG_GET_RGB(255, 255, 255));
602 break;
603
605 Set_Count(2);
606 Set_Color(0, SG_GET_RGB(255, 0, 255));
607 Set_Color(1, SG_GET_RGB(255, 255, 255));
608 break;
609
611 Set_Count(2);
612 Set_Color(0, SG_GET_RGB(255, 255, 0));
613 Set_Color(1, SG_GET_RGB(255, 255, 255));
614 break;
615
616 //-----------------------------------------------------
618 Set_Count(3);
619 Set_Color(0, SG_GET_RGB(255, 255, 127));
620 Set_Color(1, SG_GET_RGB(255, 127, 0));
621 Set_Color(2, SG_GET_RGB(127, 0, 0));
622 break;
623
625 Set_Count(3);
626 Set_Color(0, SG_GET_RGB(255, 255, 127));
627 Set_Color(1, SG_GET_RGB(127, 255, 0));
628 Set_Color(2, SG_GET_RGB( 0, 127, 0));
629 break;
630
632 Set_Count(3);
633 Set_Color(0, SG_GET_RGB(255, 255, 200));
634 Set_Color(1, SG_GET_RGB(127, 192, 255));
635 Set_Color(2, SG_GET_RGB( 0, 64, 127));
636 break;
637
638 //-----------------------------------------------------
640 Set_Count(2);
641 Set_Ramp(SG_GET_RGB( 0, 0, 255), SG_GET_RGB(255, 0, 0));
642 break;
643
645 Set_Count(2);
646 Set_Ramp(SG_GET_RGB( 0, 255, 0), SG_GET_RGB(255, 0, 0));
647 break;
648
650 Set_Count(2);
651 Set_Ramp(SG_GET_RGB( 0, 255, 0), SG_GET_RGB( 0, 0, 255));
652 break;
653
654 //-----------------------------------------------------
656 Set_Count(3);
657 Set_Color(0, SG_GET_RGB( 0, 0, 127));
658 Set_Color(1, SG_GET_RGB(255, 255, 255));
659 Set_Color(2, SG_GET_RGB(255, 0, 0));
660 break;
661
663 Set_Count(3);
664 Set_Color(0, SG_GET_RGB( 0, 127, 0));
665 Set_Color(1, SG_GET_RGB(255, 255, 255));
666 Set_Color(2, SG_GET_RGB(255, 0, 0));
667 break;
668
670 Set_Count(3);
671 Set_Color(0, SG_GET_RGB( 0, 127, 0));
672 Set_Color(1, SG_GET_RGB(255, 255, 255));
673 Set_Color(2, SG_GET_RGB( 0, 0, 255));
674 break;
675
676 //-----------------------------------------------------
678 Set_Count(3);
679 Set_Color(0, SG_GET_RGB( 0, 0, 127));
680 Set_Color(1, SG_GET_RGB(191, 191, 191));
681 Set_Color(2, SG_GET_RGB(127, 0, 0));
682 break;
683
685 Set_Count(5);
686 Set_Color(0, SG_GET_RGB(127, 0, 0));
687 Set_Color(1, SG_GET_RGB(255, 127, 0));
688 Set_Color(2, SG_GET_RGB(239, 239, 239));
689 Set_Color(3, SG_GET_RGB( 0, 127, 255));
690 Set_Color(4, SG_GET_RGB( 0, 0, 127));
691 break;
692
694 Set_Count(3);
695 Set_Color(0, SG_GET_RGB( 0, 127, 0));
696 Set_Color(1, SG_GET_RGB(191, 191, 191));
697 Set_Color(2, SG_GET_RGB(127, 0, 0));
698 break;
699
701 Set_Count(5);
702 Set_Color(0, SG_GET_RGB(127, 0, 0));
703 Set_Color(1, SG_GET_RGB(255, 127, 0));
704 Set_Color(2, SG_GET_RGB(239, 239, 239));
705 Set_Color(3, SG_GET_RGB( 0, 255, 127));
706 Set_Color(4, SG_GET_RGB( 0, 127, 0));
707 break;
708
710 Set_Count(5);
711 Set_Color(0, SG_GET_RGB( 0, 127, 0));
712 Set_Color(1, SG_GET_RGB(127, 255, 0));
713 Set_Color(2, SG_GET_RGB(191, 191, 191));
714 Set_Color(3, SG_GET_RGB( 0, 127, 255));
715 Set_Color(4, SG_GET_RGB( 0, 0, 127));
716 break;
717
718 //-----------------------------------------------------
720 Set_Count(3);
721 Set_Color(0, SG_GET_RGB( 0, 0, 255));
722 Set_Color(1, SG_GET_RGB(255, 255, 0));
723 Set_Color(2, SG_GET_RGB(255, 0, 0));
724 break;
725
727 Set_Count(3);
728 Set_Color(0, SG_GET_RGB( 0, 127, 0));
729 Set_Color(1, SG_GET_RGB(255, 255, 0));
730 Set_Color(2, SG_GET_RGB(255, 0, 0));
731 break;
732
734 Set_Count(3);
735 Set_Color(0, SG_GET_RGB(200, 0, 0));
736 Set_Color(1, SG_GET_RGB(255, 255, 127));
737 Set_Color(2, SG_GET_RGB( 0, 63, 0));
738 break;
739
741 Set_Count(3);
742 Set_Color(0, SG_GET_RGB( 0, 127, 0));
743 Set_Color(1, SG_GET_RGB(255, 255, 0));
744 Set_Color(2, SG_GET_RGB( 0, 0, 255));
745 break;
746
747 //-----------------------------------------------------
749 Set_Count(5);
750 Set_Color(0, SG_GET_RGB(127, 0, 127));
751 Set_Color(1, SG_GET_RGB(255, 0, 0));
752 Set_Color(2, SG_GET_RGB( 0, 255, 0));
753 Set_Color(3, SG_GET_RGB( 0, 0, 255));
754 Set_Color(4, SG_GET_RGB(127, 0, 127));
755 break;
756
758 Set_Count(5);
759 Set_Color(0, SG_GET_RGB(127, 127, 0));
760 Set_Color(1, SG_GET_RGB(255, 0, 0));
761 Set_Color(2, SG_GET_RGB( 0, 0, 255));
762 Set_Color(3, SG_GET_RGB( 0, 255, 0));
763 Set_Color(4, SG_GET_RGB(127, 127, 0));
764 break;
765
767 Set_Count(5);
768 Set_Color(0, SG_GET_RGB( 0, 127, 127));
769 Set_Color(1, SG_GET_RGB( 0, 255, 0));
770 Set_Color(2, SG_GET_RGB(255, 0, 0));
771 Set_Color(3, SG_GET_RGB( 0, 0, 255));
772 Set_Color(4, SG_GET_RGB( 0, 127, 127));
773 break;
774
775 case SG_COLORS_NEON:
776 Set_Count(7);
777 Set_Color(0, SG_GET_RGB( 0, 0, 0));
778 Set_Color(1, SG_GET_RGB(255, 0, 0));
779 Set_Color(2, SG_GET_RGB( 0, 0, 0));
780 Set_Color(3, SG_GET_RGB(255, 255, 0));
781 Set_Color(4, SG_GET_RGB( 0, 0, 0));
782 Set_Color(5, SG_GET_RGB( 0, 255, 0));
783 Set_Color(6, SG_GET_RGB( 0, 0, 0));
784 break;
785
786 //-----------------------------------------------------
788 Set_Count(5);
789 Set_Color(0, SG_GET_RGB( 0, 143, 127));
790 Set_Color(1, SG_GET_RGB(127, 255, 0));
791 Set_Color(2, SG_GET_RGB(255, 255, 127));
792 Set_Color(3, SG_GET_RGB(255, 192, 0));
793 Set_Color(4, SG_GET_RGB(192, 143, 0));
794 break;
795
797 Set_Count(3);
798 Set_Color(0, SG_GET_RGB( 0, 128, 0));
799 Set_Color(1, SG_GET_RGB(255, 255, 127));
800 Set_Color(2, SG_GET_RGB(127, 63, 63));
801 break;
802
804 Set_Count(6);
805 Set_Color(0, SG_GET_RGB( 0, 191, 191));
806 Set_Color(1, SG_GET_RGB( 0, 255, 0));
807 Set_Color(2, SG_GET_RGB(255, 255, 0));
808 Set_Color(3, SG_GET_RGB(255, 127, 0));
809 Set_Color(4, SG_GET_RGB(191, 152, 110));
810 Set_Color(5, SG_GET_RGB(199, 199, 199));
811 break;
812
814 Set_Count(9);
815 Set_Color(0, SG_GET_RGB(177, 242, 212));
816 Set_Color(1, SG_GET_RGB(248, 252, 179));
817 Set_Color(2, SG_GET_RGB( 11, 128, 064));
818 Set_Color(3, SG_GET_RGB(248, 202, 80));
819 Set_Color(4, SG_GET_RGB(158, 30, 0));
820 Set_Color(5, SG_GET_RGB(128, 064, 064));
821 Set_Color(6, SG_GET_RGB(185, 121, 076));
822 Set_Color(7, SG_GET_RGB(179, 179, 179));
823 Set_Color(8, SG_GET_RGB(255, 255, 255));
824 break;
825
826 //-----------------------------------------------------
828 Set_Count(5);
829 Set_Color(0, SG_GET_RGB(225, 225, 225));
830 Set_Color(1, SG_GET_RGB(127, 127, 255));
831 Set_Color(2, SG_GET_RGB( 20, 20, 20));
832 Set_Color(3, SG_GET_RGB(127, 255, 127));
833 Set_Color(4, SG_GET_RGB(225, 225, 225));
834 break;
835
837 Set_Count(5);
838 Set_Color(0, SG_GET_RGB(225, 225, 225));
839 Set_Color(1, SG_GET_RGB(255, 127, 127));
840 Set_Color(2, SG_GET_RGB( 20, 20, 20));
841 Set_Color(3, SG_GET_RGB(127, 255, 127));
842 Set_Color(4, SG_GET_RGB(225, 225, 225));
843 break;
844
846 Set_Count(5);
847 Set_Color(0, SG_GET_RGB(225, 225, 225));
848 Set_Color(1, SG_GET_RGB(255, 127, 127));
849 Set_Color(2, SG_GET_RGB( 20, 20, 20));
850 Set_Color(3, SG_GET_RGB(127, 127, 255));
851 Set_Color(4, SG_GET_RGB(225, 225, 225));
852 break;
853
854 //-----------------------------------------------------
856 Set_Count(5);
857 Set_Color(0, SG_GET_RGB( 0, 0, 191));
858 Set_Color(1, SG_GET_RGB(255, 0, 255));
859 Set_Color(2, SG_GET_RGB(255, 0, 0));
860 Set_Color(3, SG_GET_RGB(255, 255, 0));
861 Set_Color(4, SG_GET_RGB(245, 245, 163));
862 break;
863
865 Set_Count(6);
866 Set_Color(0, SG_GET_RGB(127, 255, 255));
867 Set_Color(1, SG_GET_RGB( 0, 0, 255));
868 Set_Color(2, SG_GET_RGB(127, 0, 255));
869 Set_Color(3, SG_GET_RGB(255, 0, 0));
870 Set_Color(4, SG_GET_RGB(255, 255, 0));
871 Set_Color(5, SG_GET_RGB(255, 255, 127));
872 break;
873
874 //-----------------------------------------------------
876 Set_Count(5);
877 Set_Color(0, SG_GET_RGB(255, 255, 127));
878 Set_Color(1, SG_GET_RGB(191, 255, 0));
879 Set_Color(2, SG_GET_RGB( 0, 191, 0));
880 Set_Color(3, SG_GET_RGB( 0, 127, 255));
881 Set_Color(4, SG_GET_RGB( 0, 0, 127));
882 break;
883
884 case SG_COLORS_PRECIPITATION_2: // juergen's favorite precipitation colour ramp
885 Set_Count(22);
886 Set_Color( 0, SG_GET_RGB(216, 204, 131));
887 Set_Color( 1, SG_GET_RGB(196, 208, 111));
888 Set_Color( 2, SG_GET_RGB(184, 210, 101));
889 Set_Color( 3, SG_GET_RGB(172, 212, 91));
890 Set_Color( 4, SG_GET_RGB(139, 212, 99));
891 Set_Color( 5, SG_GET_RGB(107, 212, 107));
892 Set_Color( 6, SG_GET_RGB( 75, 212, 119));
893 Set_Color( 7, SG_GET_RGB( 42, 212, 131));
894 Set_Color( 8, SG_GET_RGB( 26, 212, 151));
895 Set_Color( 9, SG_GET_RGB( 10, 212, 172));
896 Set_Color(10, SG_GET_RGB( 30, 192, 192));
897 Set_Color(11, SG_GET_RGB( 50, 172, 212));
898 Set_Color(12, SG_GET_RGB( 70, 151, 214));
899 Set_Color(13, SG_GET_RGB( 91, 131, 216));
900 Set_Color(14, SG_GET_RGB( 75, 115, 198));
901 Set_Color(15, SG_GET_RGB( 58, 99, 180));
902 Set_Color(16, SG_GET_RGB( 42, 83, 184));
903 Set_Color(17, SG_GET_RGB( 26, 066, 188));
904 Set_Color(18, SG_GET_RGB( 26, 046, 180));
905 Set_Color(19, SG_GET_RGB( 26, 026, 166));
906 Set_Color(20, SG_GET_RGB( 38, 18, 151));
907 Set_Color(21, SG_GET_RGB( 50, 010, 131));
908 break;
909
911 Set_Count(10);
912 Set_Color( 0, SG_GET_RGB(255, 255, 185));
913 Set_Color( 1, SG_GET_RGB(229, 253, 139));
914 Set_Color( 2, SG_GET_RGB(204, 252, 94));
915 Set_Color( 3, SG_GET_RGB(178, 251, 49));
916 Set_Color( 4, SG_GET_RGB(153, 251, 0));
917 Set_Color( 5, SG_GET_RGB(128, 212, 43));
918 Set_Color( 6, SG_GET_RGB( 96, 159, 88));
919 Set_Color( 7, SG_GET_RGB( 64, 106, 133));
920 Set_Color( 8, SG_GET_RGB( 32, 53, 179));
921 Set_Color( 9, SG_GET_RGB( 0, 0, 123));
922 break;
923
925 Set_Count(10);
926 Set_Color( 0, SG_GET_RGB(255, 255, 200));
927 Set_Color( 1, SG_GET_RGB(227, 254, 145));
928 Set_Color( 2, SG_GET_RGB(160, 254, 125));
929 Set_Color( 3, SG_GET_RGB( 93, 254, 168));
930 Set_Color( 4, SG_GET_RGB(027, 237, 211));
931 Set_Color( 5, SG_GET_RGB( 0, 191, 254));
932 Set_Color( 6, SG_GET_RGB( 0, 146, 245));
933 Set_Color( 7, SG_GET_RGB( 0, 100, 210));
934 Set_Color( 8, SG_GET_RGB( 0, 55, 176));
935 Set_Color( 9, SG_GET_RGB( 62, 0, 142));
936 break;
937
939 Set_Count(10);
940 Set_Color( 0, SG_GET_RGB(254, 135, 000));
941 Set_Color( 1, SG_GET_RGB(254, 194, 063));
942 Set_Color( 2, SG_GET_RGB(254, 254, 126));
943 Set_Color( 3, SG_GET_RGB(231, 231, 227));
944 Set_Color( 4, SG_GET_RGB(132, 222, 254));
945 Set_Color( 5, SG_GET_RGB(042, 163, 239));
946 Set_Color( 6, SG_GET_RGB(000, 105, 224));
947 Set_Color( 7, SG_GET_RGB(000, 047, 210));
948 Set_Color( 8, SG_GET_RGB(000, 001, 156));
949 Set_Color( 9, SG_GET_RGB(000, 000, 103));
950 break;
951
952 //-----------------------------------------------------
954 Set_Count(5);
955 Set_Color(0, SG_GET_RGB(255, 252, 158));
956 Set_Color(1, SG_GET_RGB(192, 212, 100));
957 Set_Color(2, SG_GET_RGB(128, 172, 58));
958 Set_Color(3, SG_GET_RGB( 64, 132, 88));
959 Set_Color(4, SG_GET_RGB( 0, 94, 118));
960 break;
961
962 //-----------------------------------------------------
964 Set_Count(11);
965 Set_Color( 0, SG_GET_RGB( 37, 57, 175));
966 Set_Color( 1, SG_GET_RGB( 40, 127, 251));
967 Set_Color( 2, SG_GET_RGB( 50, 190, 255));
968 Set_Color( 3, SG_GET_RGB(106, 235, 255));
969 Set_Color( 4, SG_GET_RGB(138, 236, 174));
970 Set_Color( 5, SG_GET_RGB(205, 255, 162));
971 Set_Color( 6, SG_GET_RGB(240, 236, 121));
972 Set_Color( 7, SG_GET_RGB(255, 189, 87));
973 Set_Color( 8, SG_GET_RGB(255, 161, 68));
974 Set_Color( 9, SG_GET_RGB(255, 186, 133));
975 Set_Color(10, SG_GET_RGB(255, 255, 255));
976 break;
977
979 Set_Count(8);
980 Set_Color(0, SG_GET_RGB(171, 43, 0));
981 Set_Color(1, SG_GET_RGB(255, 127, 0));
982 Set_Color(2, SG_GET_RGB(255, 255, 0));
983 Set_Color(3, SG_GET_RGB( 0, 255, 0));
984 Set_Color(4, SG_GET_RGB( 0, 255, 255));
985 Set_Color(5, SG_GET_RGB( 0, 0, 255));
986 Set_Color(6, SG_GET_RGB(255, 0, 255));
987 Set_Color(7, SG_GET_RGB(255, 255, 255));
988 break;
989
991 Set_Count(9);
992 Set_Color(0, SG_GET_RGB(000, 001, 205));
993 Set_Color(1, SG_GET_RGB(000, 132, 254));
994 Set_Color(1, SG_GET_RGB(000, 227, 254));
995 Set_Color(1, SG_GET_RGB(001, 167, 076));
996 Set_Color(1, SG_GET_RGB(118, 218, 076));
997 Set_Color(1, SG_GET_RGB(186, 255, 127));
998 Set_Color(1, SG_GET_RGB(254, 244, 152));
999 Set_Color(1, SG_GET_RGB(254, 203, 128));
1000 Set_Color(1, SG_GET_RGB(254, 172, 000));
1001 break;
1002
1003 //-----------------------------------------------------
1004// case SG_COLORS_COUNT:
1005// Set_Count(nColors);
1006// Random();
1007// break;
1008
1009 default:
1010 return( false );
1011 }
1012
1013 //-----------------------------------------------------
1014 if( bRevert )
1015 {
1016 Revert();
1017 }
1018
1019 if( nColors > 0 )
1020 {
1021 Set_Count(nColors);
1022 }
1023
1024 return( true );
1025}
1026
1027//---------------------------------------------------------
1028bool CSG_Colors::Set_Predefined(const CSG_String &Name, bool bRevert, int nColors)
1029{
1030 int Index;
1031
1032 for(int Index=0; Index<SG_COLORS_COUNT; Index++)
1033 {
1034 if( Name.Cmp(Get_Predefined_Name(Index, false)) == 0 )
1035 {
1036 return( Set_Predefined(Index, bRevert, nColors) );
1037 }
1038 }
1039
1040 if( Name.asInt(Index) )
1041 {
1042 return( Set_Predefined(Index, bRevert, nColors) );
1043 }
1044
1045 return( false );
1046}
1047
1048//---------------------------------------------------------
1050{
1051 if( nColors > 1 )
1052 {
1053 m_nColors = nColors;
1054 m_Colors = (long *)SG_Realloc(m_Colors, m_nColors * sizeof(long));
1055
1056 double d = 0., dStep = 2. * M_PI / (m_nColors - 1.);
1057
1058 for(int i=0; i<m_nColors; i++, d+=dStep)
1059 {
1060 Set_Color(i,
1061 (int)(d < M_PI / 2 ? 0 : 128 - 127 * sin(M_PI - d)),
1062 (int)(128 - 127 * cos(d)),
1063 (int)(d > M_PI * 3 / 2 ? 0 : 128 + 127 * sin(d))
1064 );
1065 }
1066
1067 return( true );
1068 }
1069
1070 return( false );
1071}
1072
1073//---------------------------------------------------------
1074bool CSG_Colors::Set_Ramp(long Color_A, long Color_B)
1075{
1076 return( Set_Ramp(Color_A, Color_B, 0, Get_Count() - 1) );
1077}
1078
1079//---------------------------------------------------------
1080bool CSG_Colors::Set_Ramp(long Color_A, long Color_B, int iColor_A, int iColor_B)
1081{
1082 if( iColor_A > iColor_B )
1083 {
1084 int i = iColor_A;
1085 iColor_A = iColor_B;
1086 iColor_B = i;
1087 }
1088
1089 if( iColor_A < 0 )
1090 {
1091 iColor_A = 0;
1092 }
1093
1094 if( iColor_B >= Get_Count() )
1095 {
1096 iColor_B = Get_Count() - 1;
1097 }
1098
1099 //-----------------------------------------------------
1100 int n = iColor_B - iColor_A;
1101
1102 if( n > 0 )
1103 {
1104 int ar = SG_GET_R(Color_A);
1105 double dr = (double)(SG_GET_R(Color_B) - ar) / (double)n;
1106
1107 int ag = SG_GET_G(Color_A);
1108 double dg = (double)(SG_GET_G(Color_B) - ag) / (double)n;
1109
1110 int ab = SG_GET_B(Color_A);
1111 double db = (double)(SG_GET_B(Color_B) - ab) / (double)n;
1112
1113 for(int i=0; i<=n; i++)
1114 {
1115 Set_Color(iColor_A + i,
1116 (int)(ar + i * dr),
1117 (int)(ag + i * dg),
1118 (int)(ab + i * db)
1119 );
1120 }
1121
1122 return( true );
1123 }
1124
1125 return( false );
1126}
1127
1128//---------------------------------------------------------
1129bool CSG_Colors::Set_Ramp_Brighness(int Brightness_A, int Brightness_B)
1130{
1131 return( Set_Ramp_Brighness(Brightness_A, Brightness_B, 0, Get_Count() - 1) );
1132}
1133
1134//---------------------------------------------------------
1135bool CSG_Colors::Set_Ramp_Brighness(int Brightness_A, int Brightness_B, int iColor_A, int iColor_B)
1136{
1137 if( iColor_A > iColor_B )
1138 {
1139 int i = iColor_A;
1140 iColor_A = iColor_B;
1141 iColor_B = i;
1142 }
1143
1144 if( iColor_A < 0 )
1145 {
1146 iColor_A = 0;
1147 }
1148
1149 if( iColor_B >= Get_Count() )
1150 {
1151 iColor_B = Get_Count() - 1;
1152 }
1153
1154 //-----------------------------------------------------
1155 int n = iColor_B - iColor_A;
1156
1157 if( n > 0 )
1158 {
1159 double dBrightness = (double)(Brightness_B - Brightness_A) / (double)n;
1160
1161 for(int i=0; i<=n; i++)
1162 {
1163 Set_Brightness(iColor_A + i, (int)(Brightness_A + i * dBrightness));
1164 }
1165
1166 return( true );
1167 }
1168
1169 return( false );
1170}
1171
1172
1174// //
1176
1177//---------------------------------------------------------
1179{
1180 for(int i=0; i<Get_Count(); i++)
1181 {
1182 Set_Color(i,
1183 (int)(255.0 * (double)rand() / (double)RAND_MAX),
1184 (int)(255.0 * (double)rand() / (double)RAND_MAX),
1185 (int)(255.0 * (double)rand() / (double)RAND_MAX)
1186 );
1187 }
1188
1189 return( Get_Count() > 0 );
1190}
1191
1192//---------------------------------------------------------
1194{
1195 for(int i=0; i<Get_Count(); i++)
1196 {
1197 Set_Color(i, 255 - Get_Red(i), 255 - Get_Green(i), 255 - Get_Blue(i));
1198 }
1199
1200 return( Get_Count() > 0 );
1201}
1202
1203//---------------------------------------------------------
1205{
1206 for(int i=0, j=Get_Count()-1; i<j; i++, j--)
1207 {
1208 long c = Get_Color(j);
1209 Set_Color(j, Get_Color(i));
1210 Set_Color(i, c);
1211 }
1212
1213 return( Get_Count() > 0 );
1214}
1215
1216//---------------------------------------------------------
1218{
1219 for(int i=0; i<Get_Count(); i++)
1220 {
1221 long c = Get_Brightness(i);
1222
1223 Set_Color(i, c, c, c);
1224 }
1225
1226 return( Get_Count() > 0 );
1227}
1228
1229
1231// //
1233
1234//---------------------------------------------------------
1236{
1237 Create(Colors);
1238
1239 return( *this );
1240}
1241
1242//---------------------------------------------------------
1244{
1245 return( Create(Colors) );
1246}
1247
1248//---------------------------------------------------------
1250{
1251 return( pColors ? Create(*pColors) : false );
1252}
1253
1254
1256// //
1258
1259//---------------------------------------------------------
1260#define COLORS_SERIAL_VERSION_BINARY "SAGA_COLORPALETTE_VERSION_0.100_BINARY"
1261#define COLORS_SERIAL_VERSION__ASCII "SAGA_COLORPALETTE_VERSION_0.100__ASCII"
1262
1263//---------------------------------------------------------
1264bool CSG_Colors::Load(const CSG_String &File_Name)
1265{
1266 CSG_File Stream;
1267
1268 if( !Stream.Open(File_Name, SG_FILE_R, true) )
1269 {
1270 return( false );
1271 }
1272
1273 CSG_String Version;
1274
1275 Stream.Read(Version, sizeof(COLORS_SERIAL_VERSION__ASCII));
1276
1277 //-----------------------------------------------------
1278 if( Version.Find(COLORS_SERIAL_VERSION__ASCII) == 0 )
1279 {
1280 return( Serialize(Stream, false, false) );
1281 }
1282
1283 //-----------------------------------------------------
1284 Stream.Seek_Start();
1285 Stream.Read(Version, sizeof(COLORS_SERIAL_VERSION_BINARY));
1286
1287 if( Version.Find(COLORS_SERIAL_VERSION_BINARY) == 0 )
1288 {
1289 int nColors;
1290
1291 Stream.Read(&nColors, sizeof(nColors));
1292
1293 if( Set_Count(nColors) ) // different os, different sizeof(long) !!
1294 {
1295 size_t ValueSize = (size_t)((Stream.Length() - (sizeof(COLORS_SERIAL_VERSION_BINARY) + sizeof(int))) / nColors);
1296
1297 if( ValueSize > 0 )
1298 {
1299 BYTE *c = (BYTE *)SG_Malloc(ValueSize);
1300
1301 for(int i=0; i<nColors; i++)
1302 {
1303 Stream.Read(c, ValueSize);
1304
1305 Set_Color(i, c[0], c[1], c[2]);
1306 }
1307
1308 SG_Free(c);
1309 }
1310
1311 return( true );
1312 }
1313 }
1314
1315 //-----------------------------------------------------
1316 else // SAGA 1.x compatibility...
1317 {
1318 short nColors;
1319
1320 Stream.Seek_Start();
1321 Stream.Read(&nColors, sizeof(short));
1322
1323 if( Stream.Length() == (int)(sizeof(short) + 3 * nColors) && Set_Count(nColors) )
1324 {
1325 BYTE *R = (BYTE *)SG_Malloc(nColors * sizeof(BYTE)); Stream.Read(R, nColors * sizeof(BYTE));
1326 BYTE *G = (BYTE *)SG_Malloc(nColors * sizeof(BYTE)); Stream.Read(G, nColors * sizeof(BYTE));
1327 BYTE *B = (BYTE *)SG_Malloc(nColors * sizeof(BYTE)); Stream.Read(B, nColors * sizeof(BYTE));
1328
1329 for(int i=0; i<nColors; i++)
1330 {
1331 Set_Color(i, R[i], G[i], B[i]);
1332 }
1333
1334 SG_Free(R); SG_Free(G); SG_Free(B);
1335
1336 return( true );
1337 }
1338 }
1339
1340 //-----------------------------------------------------
1341 return( false );
1342}
1343
1344//---------------------------------------------------------
1345bool CSG_Colors::Save(const CSG_String &File_Name, bool bBinary)
1346{
1347 CSG_File Stream;
1348
1349 if( Stream.Open(File_Name, SG_FILE_W, bBinary) )
1350 {
1351 if( bBinary )
1352 {
1354 }
1355 else
1356 {
1357 Stream.Write(COLORS_SERIAL_VERSION__ASCII); Stream.Write("\n");
1358 }
1359
1360 Serialize(Stream, true, bBinary);
1361
1362 return( true );
1363 }
1364
1365 return( false );
1366}
1367
1368
1370// //
1372
1373//---------------------------------------------------------
1374bool CSG_Colors::Serialize(CSG_File &Stream, bool bSave, bool bBinary)
1375{
1376 if( Stream.is_Open() )
1377 {
1378 //-------------------------------------------------
1379 if( bBinary )
1380 {
1381 if( bSave )
1382 {
1383 if( m_nColors > 0 )
1384 {
1385 Stream.Write(&m_nColors, sizeof(m_nColors));
1386 Stream.Write(m_Colors, sizeof(long), m_nColors);
1387 }
1388 }
1389 else
1390 {
1391 int nColors;
1392
1393 Stream.Read(&nColors, sizeof(m_nColors));
1394
1395 if( Set_Count(nColors) )
1396 {
1397 Stream.Read(m_Colors, sizeof(long), m_nColors);
1398 }
1399 }
1400
1401 return( true );
1402 }
1403
1404 //-------------------------------------------------
1405 else
1406 {
1407 if( bSave )
1408 {
1409 if( Get_Count() > 0 )
1410 {
1411 Stream.Printf("%d\n", Get_Count());
1412
1413 for(int i=0; i<Get_Count(); i++)
1414 {
1415 Stream.Printf("%03d %03d %03d\n", (int)Get_Red(i), (int)Get_Green(i), (int)Get_Blue(i));
1416 }
1417 }
1418 }
1419 else
1420 {
1421 CSG_String sLine;
1422
1423 while( Stream.Read_Line(sLine) && sLine.is_Empty() ) {} // skip empty lines
1424
1425 if( Set_Count(sLine.asInt()) )
1426 {
1427 for(int i=0; i<Get_Count(); i++)
1428 {
1429 Stream.Read_Line(sLine);
1430
1431 Set_Color(i,
1432 sLine .asInt(),
1433 sLine.AfterFirst(' ').asInt(),
1434 sLine.AfterLast (' ').asInt()
1435 );
1436 }
1437 }
1438 }
1439
1440 return( true );
1441 }
1442 }
1443
1444 return( false );
1445}
1446
1447//---------------------------------------------------------
1449{
1450 if( Get_Count() > 0 )
1451 {
1452 String.Clear();
1453
1454 for(int i=0; i<Get_Count(); i++)
1455 {
1456 String += CSG_String::Format("%03d %03d %03d;", (int)Get_Red(i), (int)Get_Green(i), (int)Get_Blue(i));
1457 }
1458
1459 return( true );
1460 }
1461
1462 return( false );
1463}
1464
1465//---------------------------------------------------------
1467{
1468 if( Set_Count((int)String.Length() / 12) )
1469 {
1470 for(int i=0, j=0; i<Get_Count(); i++, j+=12)
1471 {
1472 Set_Color(i,
1473 String.Mid(j + 0, 4).asInt(),
1474 String.Mid(j + 4, 4).asInt(),
1475 String.Mid(j + 8, 4).asInt()
1476 );
1477 }
1478
1479 return( true );
1480 }
1481
1482 return( false );
1483}
1484
1485
1487// //
1488// //
1489// //
1491
1492//---------------------------------------------------------
#define COLORS_SERIAL_VERSION_BINARY
CSG_String SG_Colors_Get_Name(int Index)
#define MAKE_NAME(name)
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)
#define SG_GET_B(rgb)
Definition api_core.h:1302
#define SG_GET_G(rgb)
Definition api_core.h:1301
SAGA_API_DLL_EXPORT void * SG_Malloc(size_t size)
SAGA_API_DLL_EXPORT void SG_Free(void *memblock)
#define SG_GET_R(rgb)
Definition api_core.h:1300
SAGA_API_DLL_EXPORT void * SG_Realloc(void *memblock, size_t size)
#define SG_GET_RGBA(r, g, b, a)
Definition api_core.h:1298
#define SG_GET_RGB(r, g, b)
Definition api_core.h:1297
#define _TL(s)
Definition api_core.h:1568
@ SG_FILE_W
Definition api_core.h:1115
@ SG_FILE_R
Definition api_core.h:1114
@ SG_COLORS_SPECTRUM_3
Definition api_core.h:1397
@ SG_COLORS_BLUE_YELLOW_RED
Definition api_core.h:1365
@ SG_COLORS_DEFAULT_BRIGHT
Definition api_core.h:1330
@ SG_COLORS_YELLOW_WHITE
Definition api_core.h:1345
@ SG_COLORS_TOPOGRAPHY_3
Definition api_core.h:1377
@ SG_COLORS_WHITE_GREEN
Definition api_core.h:1340
@ SG_COLORS_GREEN_BLUE
Definition api_core.h:1353
@ SG_COLORS_BLACK_GREEN
Definition api_core.h:1336
@ SG_COLORS_PRECIPITATION_1
Definition api_core.h:1387
@ SG_COLORS_PRECIPITATION_3
Definition api_core.h:1389
@ SG_COLORS_WHITE_RED
Definition api_core.h:1339
@ SG_COLORS_RED_GREY_BLUE
Definition api_core.h:1360
@ SG_COLORS_GREEN_WHITE_RED
Definition api_core.h:1356
@ SG_COLORS_WHITE_BLUE
Definition api_core.h:1341
@ SG_COLORS_RED_GREY_GREEN
Definition api_core.h:1362
@ SG_COLORS_RAINBOW_2
Definition api_core.h:1332
@ SG_COLORS_GREEN_GREY_BLUE
Definition api_core.h:1363
@ SG_COLORS_RED_BLUE_GREEN
Definition api_core.h:1371
@ SG_COLORS_BLACK_WHITE
Definition api_core.h:1334
@ SG_COLORS_GREEN_YELLOW_RED
Definition api_core.h:1366
@ SG_COLORS_YELLOW_RED
Definition api_core.h:1347
@ SG_COLORS_NEON
Definition api_core.h:1373
@ SG_COLORS_SPECTRUM_2
Definition api_core.h:1396
@ SG_COLORS_GREEN_GREY_RED
Definition api_core.h:1361
@ SG_COLORS_THERMAL_1
Definition api_core.h:1384
@ SG_COLORS_GREEN_WHITE_BLUE
Definition api_core.h:1357
@ SG_COLORS_BLACK_BLUE
Definition api_core.h:1337
@ SG_COLORS_RED_GREEN_BLUE
Definition api_core.h:1370
@ SG_COLORS_PRECIPITATION_4
Definition api_core.h:1390
@ SG_COLORS_RED_YELLOW_GREEN
Definition api_core.h:1367
@ SG_COLORS_GREEN_YELLOW_BLUE
Definition api_core.h:1368
@ SG_COLORS_ASPECT_3
Definition api_core.h:1382
@ SG_COLORS_YELLOW_BLUE
Definition api_core.h:1349
@ SG_COLORS_TOPOGRAPHY_2
Definition api_core.h:1376
@ SG_COLORS_BLACK_RED
Definition api_core.h:1335
@ SG_COLORS_BLUE_WHITE_RED
Definition api_core.h:1355
@ SG_COLORS_VEGETATION
Definition api_core.h:1393
@ SG_COLORS_TOPOGRAPHY_4
Definition api_core.h:1378
@ SG_COLORS_MAGENTA_WHITE
Definition api_core.h:1344
@ SG_COLORS_SPECTRUM_1
Definition api_core.h:1395
@ SG_COLORS_ASPECT_2
Definition api_core.h:1381
@ SG_COLORS_ASPECT_1
Definition api_core.h:1380
@ SG_COLORS_GREEN_RED
Definition api_core.h:1352
@ SG_COLORS_RAINBOW
Definition api_core.h:1331
@ SG_COLORS_YELLOW_GREEN
Definition api_core.h:1348
@ SG_COLORS_CYAN_WHITE
Definition api_core.h:1343
@ SG_COLORS_THERMAL_2
Definition api_core.h:1385
@ SG_COLORS_GREEN_RED_BLUE
Definition api_core.h:1372
@ SG_COLORS_TOPOGRAPHY
Definition api_core.h:1375
@ SG_COLORS_BLUE_RED
Definition api_core.h:1351
@ SG_COLORS_BLUE_GREY_RED
Definition api_core.h:1359
@ SG_COLORS_DEFAULT
Definition api_core.h:1329
@ SG_COLORS_PRECIPITATION_5
Definition api_core.h:1391
@ SG_COLORS_COUNT
Definition api_core.h:1399
@ SG_COLORS_PRECIPITATION_2
Definition api_core.h:1388
bool Revert(void)
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
Definition api_core.h:1447
bool Set_Blue(int Index, int Value)
bool Greyscale(void)
bool Set_Default(int nColors=11)
long Get_Blue(int Index) const
Definition api_core.h:1446
CSG_Colors & operator=(const CSG_Colors &Colors)
long Get_Color(int Index) const
Definition api_core.h:1443
bool Set_Count(int nColors)
bool Load(const CSG_String &File_Name)
bool Set_Color(int Index, long Color)
bool Serialize(CSG_File &Stream, bool bSave, bool bBinary)
static int Get_Predefined_Count(void)
long Get_Red(int Index) const
Definition api_core.h:1444
CSG_Colors(void)
bool Set_Ramp(long Color_A, long Color_B)
bool to_Text(CSG_String &String)
bool Save(const CSG_String &File_Name, bool bBinary)
bool Set_Brightness(int Index, int Value)
virtual ~CSG_Colors(void)
long Get_Green(int Index) const
Definition api_core.h:1445
bool Set_Ramp_Brighness(int Brightness_A, int Brightness_B)
bool Set_Palette(int Index, bool bRevert=false, int nColors=0)
Definition api_core.h:1467
bool Create(void)
bool Assign(const CSG_Colors &Colors)
void Destroy(void)
int Get_Count(void) const
Definition api_core.h:1431
bool Set_Predefined(int Index, bool bRevert=false, int nColors=0)
bool Invert(void)
bool Random(void)
bool Set_Red(int Index, int Value)
long Get_Interpolated(double Index) const
Definition api_core.h:1449
sLong Length(void) const
Definition api_file.cpp:230
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
bool is_Open(void) const
Definition api_core.h:1149
bool Read_Line(CSG_String &Line) const
Definition api_file.cpp:399
size_t Write(void *Buffer, size_t Size, size_t Count=1) const
Definition api_file.cpp:370
size_t Read(void *Buffer, size_t Size, size_t Count=1) const
Definition api_file.cpp:338
int Printf(const char *Format,...)
Definition api_file.cpp:287
bool Seek_Start(void) const
Definition api_file.cpp:261
static double Get_Uniform(void)
size_t Length(void) const
CSG_String AfterFirst(char Character) const
const char * b_str(void) const
CSG_String AfterLast(char Character) const
int Cmp(const CSG_String &String) const
void Clear(void)
static CSG_String Format(const char *Format,...)
int Find(char Character, bool fromEnd=false) const
SG_Char Get_Char(size_t i) const
int asInt(void) const
int Printf(const char *Format,...)
bool is_Empty(void) const
CSG_String Mid(size_t first, size_t count=0) const
#define B
#define M_PI
Definition mat_tools.h:96