Prechádzať zdrojové kódy

new algorithmic Light color server theming

Marino Faggiana 7 rokov pred
rodič
commit
30b2536299

+ 10 - 2
iOSClient/AppDelegate.m

@@ -1011,10 +1011,18 @@
     
         if ([NCBrandOptions sharedInstance].use_themingColor && capabilities.themingColor.length == 7) {
         
-            if ([[capabilities.themingColor substringWithRange:NSMakeRange(0, 6)] isEqualToString:@"#FFFFF"])
+            BOOL isLight = [CCGraphics isLight:[CCGraphics colorFromHexString:capabilities.themingColor]];
+            
+            if (isLight) {
+                
+                // Activity
+                [[NCManageDatabase sharedInstance] addActivityClient:@"" fileID:@"" action:k_activityDebugActionCapabilities selector:@"Server Theming" note:NSLocalizedString(@"_theming_is_light_", nil) type:k_activityTypeFailure verbose:k_activityVerboseDefault activeUrl:_activeUrl];
+                
                 [NCBrandColor sharedInstance].brand = [NCBrandColor sharedInstance].customer;
-            else
+                
+            } else {
                 [NCBrandColor sharedInstance].brand = [CCGraphics colorFromHexString:capabilities.themingColor];
+            }
             
         } else {
             

+ 2 - 0
iOSClient/Supporting Files/en.lproj/Localizable.strings

@@ -411,6 +411,8 @@
 "_search_all_folders_"          = "Search in all folders";
 "_search_sub_folder_"           = "Search here and in subfolders";
 
+"_theming_is_light_"            = "Server theming too light color, not applicable";
+
 // Security
 
 "_reload_folder_"               = "Please reload folder";

+ 2 - 0
iOSClient/Utility/CCGraphics.h

@@ -47,6 +47,8 @@
 
 + (UIImage *)blurryImage:(UIImage *)image withBlurLevel:(CGFloat)blur toSize:(CGSize)toSize;
 
++ (BOOL)isLight:(UIColor *)color;
+
 @end
 
 @interface CCAvatar : UIImageView

+ 31 - 0
iOSClient/Utility/CCGraphics.m

@@ -328,6 +328,37 @@
     return [CCGraphics scaleImage:blurImage toSize:toSize isAspectRation:YES];
 }
 
+// ------------------------------------------------------------------------------------------------------
+// MARK: Is Light Color
+// ------------------------------------------------------------------------------------------------------
+
+/*
+Color visibility can be determined according to the following algorithm:
+
+(This is a suggested algorithm that is still open to change.)
+
+Two colors provide good color visibility if the brightness difference and the color difference between the two colors are greater than a set range.
+
+Color brightness is determined by the following formula:
+((Red value X 299) + (Green value X 587) + (Blue value X 114)) / 1000
+Note: This algorithm is taken from a formula for converting RGB values to YIQ values. This brightness value gives a perceived brightness for a color.
+
+Color difference is determined by the following formula:
+(maximum (Red value 1, Red value 2) - minimum (Red value 1, Red value 2)) + (maximum (Green value 1, Green value 2) - minimum (Green value 1, Green value 2)) + (maximum (Blue value 1, Blue value 2) - minimum (Blue value 1, Blue value 2))
+*/
+
++ (BOOL)isLight:(UIColor *)color
+{
+    const CGFloat *componentColors = CGColorGetComponents(color.CGColor);
+    CGFloat colorBrightness = ((componentColors[0] * 299) + (componentColors[1] * 587) + (componentColors[2] * 114)) / 1000;
+    
+    if (colorBrightness < 0.8) { // STD 0.5
+        return false;
+    } else {
+        return true;
+    }
+}
+
 @end
 
 // ------------------------------------------------------------------------------------------------------