Herezh_dev/Resultats/Ext_visu/rgb.cc

107 lines
2.7 KiB
C++

// This file is part of the Herezh++ application.
//
// The finite element software Herezh++ is dedicated to the field
// of mechanics for large transformations of solid structures.
// It is developed by Gérard Rio (APP: IDDN.FR.010.0106078.000.R.P.2006.035.20600)
// INSTITUT DE RECHERCHE DUPUY DE LÔME (IRDL) <https://www.irdl.fr/>.
//
// Herezh++ is distributed under GPL 3 license ou ultérieure.
//
// Copyright (C) 1997-2021 Université Bretagne Sud (France)
// AUTHOR : Gérard Rio
// E-MAIL : gerardrio56@free.fr
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License,
// or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// For more information, please consult: <https://herezh.irdl.fr/>.
#include <stdio.h>
#include "rgb.h"
// modif gérard #include "color.h"
Rgb::Rgb()
{
r = g = b = 1.;
}
Rgb::Rgb(float ir, float ig, float ib)
{
r = ir; g = ig; b = ib;
}
///////////////////////////////////////
istream& operator>>(istream& i, Rgb& c)
{
return i >> c.r >> c.g >> c.b ;
}
ostream& operator<<(ostream& o, const Rgb& c)
{
if (c != DefautRgb)
o << " " << c.r << " " << c.g << " " << c.b ;
return o;
}
///////////////////////////////////////
Rgb operator + (Rgb c1, Rgb c2)
{
Rgb out;
out.r = c1.r + c2.r;
out.g = c1.g + c2.g;
out.b = c1.b + c2.b;
return out;
}
///////////////////////////////////////
Rgb operator * (float f, Rgb c)
{
Rgb out;
out.r = f * c.r;
out.g = f * c.g;
out.b = f * c.b;
return out;
}
///////////////////////////////////////
Rgb hexaToRgb(const char* hexacouleur)
{
Rgb out;
int r, g, b;
if (hexacouleur[0] == '#') { // notation hexa #rrggbb
char c[3] = "ff";
c[0] = hexacouleur[1];
c[1] = hexacouleur[2];
sscanf(c, "%x",&r);
c[0] = hexacouleur[3];
c[1] = hexacouleur[4];
sscanf(c, "%x",&g);
c[0] = hexacouleur[5];
c[1] = hexacouleur[6];
sscanf(c, "%x",&b);
}
/* modif gérard else { // nom symbolique (rgb.txt)
x_get_palette(hexacouleur,&r,&g,&b);
}*/
out.r = float(r) / 255.;
out.g = float(g) / 255.;
out.b = float(b) / 255.;
return out;
}