marinofaggiana 4 жил өмнө
parent
commit
a4ff5f50d3

+ 1 - 1
Share/ShareViewController.m

@@ -412,7 +412,7 @@
     else if (UTTypeConformsTo(fileUTI, kUTTypeImage)) {
         image = [UIImage imageWithContentsOfFile:[NSTemporaryDirectory() stringByAppendingString:fileName]];
         if (image) {
-            image = [NCUtility.shared resizeImage:image size:CGSizeMake(cell.frame.size.width, cell.frame.size.height)];
+            image = [image resizeImageWithSize:CGSizeMake(cell.frame.size.width, cell.frame.size.height)];
         } else {
             image = [UIImage imageNamed:@"file_photo"];
         }

+ 2 - 2
iOSClient/PeekPop/CCPeekPop.m

@@ -62,7 +62,7 @@
     }
     
     self.view.backgroundColor = NCBrandColor.shared.backgroundForm;
-    self.imagePreview.image = [NCUtility.shared resizeImage:image size:CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height)];
+    self.imagePreview.image = [image resizeImageWithSize:CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height)];
     self.preferredContentSize = CGSizeMake(self.imagePreview.image.size.width,  self.imagePreview.image.size.height + highLabelFileName);
 }
 
@@ -107,7 +107,7 @@
     [[NCCommunication shared] downloadPreviewWithFileNamePathOrFileId:fileNamePath fileNamePreviewLocalPath:fileNamePreviewLocalPath widthPreview:NCBrandGlobal.shared.sizePreview heightPreview:NCBrandGlobal.shared.sizePreview fileNameIconLocalPath:fileNameIconLocalPath sizeIcon:NCBrandGlobal.shared.sizeIcon customUserAgent:nil addCustomHeaders:nil endpointTrashbin:false useInternalEndpoint:true completionHandler:^(NSString *account, UIImage *imagePreview, UIImage *imageIcon, NSInteger errorCode,  NSString *errorDescription) {
         
         if (errorCode == 0 && imagePreview != nil) {
-            self.imagePreview.image = [NCUtility.shared resizeImage:imagePreview size:CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height)];
+            self.imagePreview.image = [imagePreview resizeImageWithSize:CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height)];
             self.preferredContentSize = CGSizeMake(self.imagePreview.image.size.width, self.imagePreview.image.size.height + highLabelFileName);
         }
     }];

+ 2 - 2
iOSClient/ScanDocument/ScanCollectionView.swift

@@ -403,7 +403,7 @@ extension DragDropViewController : UICollectionViewDataSource {
             
             // 72 DPI
             if imageWidthInPixels > 595 || imageHeightInPixels > 842  {
-                image = NCUtility.shared.resizeImage(image, size: CGSize(width: 595, height: 842)) ?? image
+                image = image.resizeImage(size: CGSize(width: 595, height: 842)) ?? image
             }
             
             cell.customImageView?.image = image
@@ -422,7 +422,7 @@ extension DragDropViewController : UICollectionViewDataSource {
             
             // 72 DPI 
             if imageWidthInPixels > 595 || imageHeightInPixels > 842  {
-                image = NCUtility.shared.resizeImage(image, size: CGSize(width: 595, height: 842)) ?? image                
+                image = image.resizeImage(size: CGSize(width: 595, height: 842)) ?? image
             }
             
             cell.customImageView?.image = self.filter(image: image)

+ 2 - 2
iOSClient/Settings/CCManageAccount.m

@@ -60,7 +60,7 @@
         UIImage *avatar = [UIImage imageWithContentsOfFile:fileNamePath];
         if (avatar) {
             
-            avatar = [NCUtility.shared resizeImage:avatar size:CGSizeMake(35, 35)];
+            avatar = [avatar resizeImageWithSize:CGSizeMake(35, 35)];
             NCAvatar *avatarImageView = [[NCAvatar alloc] initWithImage:avatar borderColor:[UIColor whiteColor] borderWidth:1];
                         
             CGSize imageSize = avatarImageView.bounds.size;
@@ -71,7 +71,7 @@
             UIGraphicsEndImageContext();
             
         } else {
-            avatar = [NCUtility.shared resizeImage:[UIImage imageNamed:@"avatarBN"] size:CGSizeMake(35, 35)];
+            avatar = [[UIImage imageNamed:@"avatarBN"] resizeImageWithSize:CGSizeMake(35, 35)];
         }
         
         row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.backgroundCell;

+ 2 - 46
iOSClient/Utility/CCGraphics.m

@@ -95,9 +95,9 @@
         originalImage = [self generateImageFromVideo:[NSTemporaryDirectory() stringByAppendingString:@"tempvideo.mp4"]];
     }
 
-    scaleImagePreview = [NCUtility.shared resizeImage:originalImage size:CGSizeMake(NCBrandGlobal.shared.sizePreview, NCBrandGlobal.shared.sizePreview)];
+    scaleImagePreview = [originalImage resizeImageWithSize:CGSizeMake(NCBrandGlobal.shared.sizePreview, NCBrandGlobal.shared.sizePreview)];
     
-    scaleImageIcon = [NCUtility.shared resizeImage:originalImage size:CGSizeMake(NCBrandGlobal.shared.sizeIcon, NCBrandGlobal.shared.sizeIcon)];
+    scaleImageIcon = [originalImage resizeImageWithSize:CGSizeMake(NCBrandGlobal.shared.sizeIcon, NCBrandGlobal.shared.sizeIcon)];
     
     scaleImagePreview = [UIImage imageWithData:UIImageJPEGRepresentation(scaleImagePreview, 0.5f)];
     scaleImageIcon = [UIImage imageWithData:UIImageJPEGRepresentation(scaleImageIcon, 0.5f)];
@@ -112,48 +112,4 @@
     return;
 }
 
-/*
-+ (UIColor *)colorFromHexString:(NSString *)hexString
-{
-    unsigned rgbValue = 0;
-    NSScanner *scanner = [NSScanner scannerWithString:hexString];
-    [scanner setScanLocation:1]; // bypass '#' character
-    [scanner scanHexInt:&rgbValue];
-    return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:1.0];
-}
-
-+ (void)settingThemingColor:(NSString *)themingColor themingColorElement:(NSString *)themingColorElement themingColorText:(NSString *)themingColorText
-{
-    UIColor *newColor, *newColorElement, *newColorText;
-    
-    // COLOR
-    if (themingColor.length == 7) {
-        newColor = [CCGraphics colorFromHexString:themingColor];
-    } else {
-        newColor = NCBrandColor.shared.customer;
-    }
-            
-    // COLOR TEXT
-    if (themingColorText.length == 7) {
-        newColorText = [CCGraphics colorFromHexString:themingColorText];
-    } else {
-        newColorText = NCBrandColor.shared.customerText;
-    }
-            
-    // COLOR ELEMENT
-    if (themingColorElement.length == 7) {
-        newColorElement = [CCGraphics colorFromHexString:themingColorElement];
-    } else {
-        if ([themingColorText isEqualToString:@"#000000"])
-            newColorElement = [UIColor blackColor];
-        else
-            newColorElement = newColor;
-    }
-            
-    NCBrandColor.shared.brand = newColor;
-    NCBrandColor.shared.brandElement = newColorElement;
-    NCBrandColor.shared.brandText = newColorText;
-}
-*/
-
 @end

+ 7 - 37
iOSClient/Utility/NCUtility.swift

@@ -112,38 +112,6 @@ class NCUtility: NSObject {
         return false
     }
     
-    @objc func resizeImage(_ image: UIImage, size: CGSize) -> UIImage? {
-        
-        let cgImage = image.cgImage!
-        var format = vImage_CGImageFormat(bitsPerComponent: 8, bitsPerPixel: 32, colorSpace: nil, bitmapInfo: CGBitmapInfo(rawValue: CGImageAlphaInfo.first.rawValue), version: 0, decode: nil, renderingIntent: CGColorRenderingIntent.defaultIntent)
-        var sourceBuffer = vImage_Buffer()
-        defer {
-            free(sourceBuffer.data)
-        }
-        var error = vImageBuffer_InitWithCGImage(&sourceBuffer, &format, nil, cgImage, numericCast(kvImageNoFlags))
-        guard error == kvImageNoError else { return nil }
-        // create a destination buffer
-        let destWidth = Int(size.width)
-        let destHeight = Int(size.height)
-        let bytesPerPixel = image.cgImage!.bitsPerPixel/8
-        let destBytesPerRow = destWidth * bytesPerPixel
-        let destData = UnsafeMutablePointer<UInt8>.allocate(capacity: destHeight * destBytesPerRow)
-        defer {
-            destData.deallocate()
-        }
-        var destBuffer = vImage_Buffer(data: destData, height: vImagePixelCount(destHeight), width: vImagePixelCount(destWidth), rowBytes: destBytesPerRow)
-        // scale the image
-        error = vImageScale_ARGB8888(&sourceBuffer, &destBuffer, nil, numericCast(kvImageHighQualityResampling))
-        guard error == kvImageNoError else { return nil }
-        // create a CGImage from vImage_Buffer
-        var destCGImage = vImageCreateCGImageFromBuffer(&destBuffer, &format, nil, nil, numericCast(kvImageNoFlags), &error)?.takeRetainedValue()
-        guard error == kvImageNoError else { return nil }
-        // create a UIImage
-        let resizedImage = destCGImage.flatMap { UIImage(cgImage: $0, scale: 0.0, orientation: image.imageOrientation) }
-        destCGImage = nil
-        return resizedImage
-    }
-    
     func cellBlurEffect(with frame: CGRect) -> UIView {
         
         let blurEffect = UIBlurEffect(style: .extraLight)
@@ -615,7 +583,7 @@ class NCUtility: NSObject {
             messageUserDefined = NSLocalizedString("_away_", comment: "")
         }
         if userStatus?.lowercased() == "dnd" {
-            onlineStatus = UIImage.init(named: "userStatusDnd")?.resizeImageUsingVImage(size: CGSize(width: 100, height: 100))
+            onlineStatus = UIImage.init(named: "userStatusDnd")?.resizeImage(size: CGSize(width: 100, height: 100))
             messageUserDefined = NSLocalizedString("_dnd_", comment: "")
         }
         if userStatus?.lowercased() == "offline" || userStatus?.lowercased() == "invisible"  {
@@ -643,6 +611,8 @@ class NCUtility: NSObject {
         if themingColor?.first == "#" {
             if let color = UIColor(hex: themingColor!) {
                 NCBrandColor.shared.brand = color
+            } else {
+                NCBrandColor.shared.brand = NCBrandColor.shared.customer
             }
         } else {
             NCBrandColor.shared.brand = NCBrandColor.shared.customer
@@ -652,6 +622,8 @@ class NCUtility: NSObject {
         if themingColorText?.first == "#" {
             if let color = UIColor(hex: themingColorText!) {
                 NCBrandColor.shared.brandText = color
+            } else {
+                NCBrandColor.shared.brandText = NCBrandColor.shared.customerText
             }
         } else {
             NCBrandColor.shared.brandText = NCBrandColor.shared.customerText
@@ -661,13 +633,11 @@ class NCUtility: NSObject {
         if themingColorElement?.first == "#" {
             if let color = UIColor(hex: themingColorElement!) {
                 NCBrandColor.shared.brandElement = color
-            }
-        } else {
-            if themingColorText == "#000000" {
-                NCBrandColor.shared.brandElement = .black
             } else {
                 NCBrandColor.shared.brandElement = NCBrandColor.shared.brand
             }
+        } else {
+            NCBrandColor.shared.brandElement = NCBrandColor.shared.brand
         }
     }
 }

+ 1 - 1
iOSClient/Utility/UIImage+Extensions.swift

@@ -26,7 +26,7 @@ import Accelerate
 
 extension UIImage {
     
-    func resizeImageUsingVImage(size:CGSize) -> UIImage? {
+    @objc func resizeImage(size:CGSize) -> UIImage? {
         
         let cgImage = self.cgImage!
         var format = vImage_CGImageFormat(bitsPerComponent: 8, bitsPerPixel: 32, colorSpace: nil, bitmapInfo: CGBitmapInfo(rawValue: CGImageAlphaInfo.first.rawValue), version: 0, decode: nil, renderingIntent: CGColorRenderingIntent.defaultIntent)