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