LKColor LKColor::MixColors(const LKColor& Color2, double fFact1) const { double fFact2 = 1.0f - fFact1; #ifdef GREYSCALE int Luminosity1 = GetLuminosity(); int Luminosity2 = Color2.GetLuminosity(); int Luminosity = (int) (fFact1 * (double) Luminosity1 + fFact2 * (double) Luminosity2); if (Luminosity > 255) Luminosity = 255; return Color(Luminosity, Alpha()); #else uint8_t red1 = Red(); uint8_t green1 = Green(); uint8_t blue1 = Blue(); uint8_t red2 = Color2.Red(); uint8_t green2 = Color2.Green(); uint8_t blue2 = Color2.Blue(); int red = (int) (fFact1 * (double) red1 + fFact2 * (double) red2); if (red > 255) red = 255; int green = (int) (fFact1 * (double) green1 + fFact2 * (double) green2); if (green > 255) green = 255; int blue = (int) (fFact1 * (double) blue1 + fFact2 * (double) blue2); if (blue > 255) blue = 255; return LKColor((uint8_t) red, (uint8_t) green, (uint8_t) blue); #endif }
constexpr Color WithAlpha(uint8_t alpha) const { #ifdef GREYSCALE return Color(GetLuminosity(), alpha); #else return Color(Red(), Green(), Blue(), alpha); #endif }
LKColor LKColor::ContrastTextColor() const { #ifdef GREYSCALE return (GetLuminosity() > 127 ? RGB_BLACK : RGB_WHITE); #else // human eye brightness color factors // Y=0.30 R + 0.59 G + 0.11 B. return ((0.30 * (double) Blue() + 0.59 * (double) Green() + 0.11 * (double) Red() > 127) ? RGB_BLACK : RGB_WHITE); #endif }
/** * Returns the shadowed version of this color. */ constexpr Color Shadow() const { #ifdef GREYSCALE return Color(GetLuminosity() * 15u / 16u); #else return Color(Red() * 15u / 16u, Green() * 15u / 16u, Blue() * 15u / 16u, Alpha()); #endif }
void main() { InitDevice(); while(1){ GetLuminosity(); GetTemperatureHumidity(); Uart1_Write_Text(&packet[0]); Delay_ms(20000); //20sec } }
/** * Compares two colors * @param a Color 1 * @param b Color 2 * @return True if colors match, False otherwise */ constexpr bool operator ==(const Color other) const { // TODO: compare alpha? #ifdef GREYSCALE return GetLuminosity() == other.GetLuminosity(); #else return value.Red() == other.value.Red() && value.Green() == other.value.Green() && value.Blue() == other.value.Blue(); #endif }
/** * Returns the highlighted version of this color. */ constexpr Color Highlight() const { #ifdef GREYSCALE return Color((GetLuminosity() + 0xff * 3) / 4); #else return Color((Red() + 0xff * 3) / 4, (Green() + 0xff * 3) / 4, (Blue() + 0xff * 3) / 4); #endif }
LKColor LKColor::ChangeBrightness(double fBrightFact) const { #ifdef GREYSCALE int Luminosity = GetLuminosity()*fBrightFact; if (Luminosity > 255) Luminosity = 255; return Color(Luminosity, Alpha()); #else int red = (int) (fBrightFact * (double) Red()); if (red > 255) red = 255; int blue = (int) (fBrightFact * (double) Blue()); if (blue > 255) blue = 255; int green = (int) (fBrightFact * (double) Green()); if (green > 255) green = 255; return LKColor((uint8_t) red, (uint8_t) green, (uint8_t) blue); #endif }
// Save(): const char * IllumiSurf_Instance::Save( const LWSaveState *saver ) { char cvalue; // Version LWSAVE_BEGIN( saver, &illumisurf_io_isfv[0], 0 ); cvalue = 1; LWSAVE_I1( saver, &cvalue, 1 ); // Blending Mode LWSAVE_BEGIN( saver, &illumisurf_io_root[ ISIOID_BLND ], 1 ); cvalue = GetBlendMode(); LWSAVE_I1( saver, &cvalue, 1 ); LWSAVE_END( saver ); // Base Intensity LWSAVE_BEGIN( saver, &illumisurf_io_root[ ISIOID_BINT ], 1 ); vparam_funcs->save( GetBaseIntensity(), saver ); LWSAVE_END( saver ); // Alternate Intensity LWSAVE_BEGIN( saver, &illumisurf_io_root[ ISIOID_AINT ], 1 ); vparam_funcs->save( GetAltIntensity(), saver ); LWSAVE_END( saver ); // Color LWSAVE_BEGIN( saver, &illumisurf_io_root[ ISIOID_COLR ], 1 ); cvalue = GetUseColor() ? 1 : 0; LWSAVE_I1( saver, &cvalue, 1 ); vparam_funcs->save( GetColor(), saver ); LWSAVE_END( saver ); // Luminosity LWSAVE_BEGIN( saver, &illumisurf_io_root[ ISIOID_LUMI ], 1 ); cvalue = GetUseLuminosity() ? 1 : 0; LWSAVE_I1( saver, &cvalue, 1 ); vparam_funcs->save( GetLuminosity(), saver ); LWSAVE_END( saver ); // Diffusion LWSAVE_BEGIN( saver, &illumisurf_io_root[ ISIOID_DIFF ], 1 ); cvalue = GetUseDiffusion() ? 1 : 0; LWSAVE_I1( saver, &cvalue, 1 ); vparam_funcs->save( GetDiffusion(), saver ); LWSAVE_END( saver ); // Specular LWSAVE_BEGIN( saver, &illumisurf_io_root[ ISIOID_SPEC ], 1 ); cvalue = GetUseSpecular() ? 1 : 0; LWSAVE_I1( saver, &cvalue, 1 ); vparam_funcs->save( GetSpecular(), saver ); LWSAVE_END( saver ); // Glossiness LWSAVE_BEGIN( saver, &illumisurf_io_root[ ISIOID_GLOS ], 1 ); cvalue = GetUseGlossiness() ? 1 : 0; LWSAVE_I1( saver, &cvalue, 1 ); vparam_funcs->save( GetGlossiness(), saver ); LWSAVE_END( saver ); // Reflection LWSAVE_BEGIN( saver, &illumisurf_io_root[ ISIOID_REFL ], 1 ); cvalue = GetUseReflection() ? 1 : 0; LWSAVE_I1( saver, &cvalue, 1 ); vparam_funcs->save( GetReflection(), saver ); LWSAVE_END( saver ); // Transparency LWSAVE_BEGIN( saver, &illumisurf_io_root[ ISIOID_TRNP ], 1 ); cvalue = GetUseTransparency() ? 1 : 0; LWSAVE_I1( saver, &cvalue, 1 ); vparam_funcs->save( GetTransparency(), saver ); LWSAVE_END( saver ); // Refraction LWSAVE_BEGIN( saver, &illumisurf_io_root[ ISIOID_REFR ], 1 ); cvalue = GetUseRefraction() ? 1 : 0; LWSAVE_I1( saver, &cvalue, 1 ); vparam_funcs->save( GetRefraction(), saver ); LWSAVE_END( saver ); // Translucency LWSAVE_BEGIN( saver, &illumisurf_io_root[ ISIOID_TRNC ], 1 ); cvalue = GetUseTranslucency() ? 1 : 0; LWSAVE_I1( saver, &cvalue, 1 ); vparam_funcs->save( GetTranslucency(), saver ); LWSAVE_END( saver ); LWSAVE_END( saver ); return NULL; }
// Load(): const char * IllumiSurf_Instance::Load( const LWLoadState *loader ) { char cvalue; if( ISIOPRE_ISFV == LWLOAD_FIND( loader, illumisurf_io_isfv ) ) { LWLOAD_I1( loader, &cvalue, 1 ); if( cvalue != 1 ) return "IllumiSurf Error: Unsupported version found, aborting load"; while( int id = LWLOAD_FIND( loader, illumisurf_io_root ) ) { switch( id ) { case ISIOPRE_BLND: LWLOAD_I1( loader, &cvalue, 1 ); SetBlendMode( (IllumiSurf_BlendModes)cvalue ); break; case ISIOPRE_BINT: vparam_funcs->load( GetBaseIntensity(), loader ); break; case ISIOPRE_AINT: vparam_funcs->load( GetAltIntensity(), loader ); break; case ISIOPRE_COLR: LWLOAD_I1( loader, &cvalue, 1 ); SetUseColor( cvalue != 0 ); vparam_funcs->load( GetColor(), loader ); break; case ISIOPRE_LUMI: LWLOAD_I1( loader, &cvalue, 1 ); SetUseLuminosity( cvalue != 0 ); vparam_funcs->load( GetLuminosity(), loader ); break; case ISIOPRE_DIFF: LWLOAD_I1( loader, &cvalue, 1 ); SetUseDiffusion( cvalue != 0 ); vparam_funcs->load( GetDiffusion(), loader ); break; case ISIOPRE_SPEC: LWLOAD_I1( loader, &cvalue, 1 ); SetUseSpecular( cvalue != 0 ); vparam_funcs->load( GetSpecular(), loader ); break; case ISIOPRE_GLOS: LWLOAD_I1( loader, &cvalue, 1 ); SetUseGlossiness( cvalue != 0 ); vparam_funcs->load( GetGlossiness(), loader ); break; case ISIOPRE_REFL: LWLOAD_I1( loader, &cvalue, 1 ); SetUseReflection( cvalue != 0 ); vparam_funcs->load( GetReflection(), loader ); break; case ISIOPRE_TRNP: LWLOAD_I1( loader, &cvalue, 1 ); SetUseTransparency( cvalue != 0 ); vparam_funcs->load( GetTransparency(), loader ); break; case ISIOPRE_REFR: LWLOAD_I1( loader, &cvalue, 1 ); SetUseRefraction( cvalue != 0 ); vparam_funcs->load( GetRefraction(), loader ); break; case ISIOPRE_TRNC: LWLOAD_I1( loader, &cvalue, 1 ); SetUseTranslucency( cvalue != 0 ); vparam_funcs->load( GetTranslucency(), loader ); break; } LWLOAD_END( loader ); // End Keyword } LWLOAD_END( loader ); // End Keyword } return NULL; }