diff --git a/Config/buck_rule_macros.bzl b/Config/buck_rule_macros.bzl index 6ec78c36be..2b3253fe5b 100644 --- a/Config/buck_rule_macros.bzl +++ b/Config/buck_rule_macros.bzl @@ -21,6 +21,7 @@ def apple_lib( deps = [], exported_deps = [], additional_linker_flags = None, + exported_preprocessor_flags = [], frameworks = [], weak_frameworks = [], swift_version = None, @@ -140,6 +141,7 @@ def apple_lib( platform_compiler_flags = platform_compiler_flags, swift_compiler_flags = swift_compiler_flags, preferred_linkage = "static", + exported_preprocessor_flags = exported_preprocessor_flags, ) def static_library( @@ -152,6 +154,7 @@ def static_library( extra_xcode_files = [], deps = [], additional_linker_flags = None, + exported_preprocessor_flags = [], frameworks = [], weak_frameworks = [], info_plist = None, @@ -161,7 +164,8 @@ def static_library( platform_compiler_flags = None, swift_compiler_flags = None, warning_as_error = False, - suppress_warnings = True): + suppress_warnings = True + ): apple_lib( name = name, srcs = srcs, @@ -175,6 +179,7 @@ def static_library( extra_xcode_files = extra_xcode_files, deps = deps, additional_linker_flags = additional_linker_flags, + exported_preprocessor_flags = exported_preprocessor_flags, frameworks = frameworks, weak_frameworks = weak_frameworks, warning_as_error = warning_as_error, diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift index d3232f0fb6..fe4bacc26c 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift @@ -244,7 +244,7 @@ final class WallpaperGalleryItemNode: GalleryItemNode { colorSignal = chatServiceBackgroundColor(wallpaper: wallpaper, mediaBox: self.context.account.postbox.mediaBox) isBlurrable = false case let .file(file): - let dimensions = file.file.dimensions ?? PixelDimensions(width: 100, height: 100) + let dimensions = file.file.dimensions ?? PixelDimensions(width: 2000, height: 4000) contentSize = dimensions.cgSize displaySize = dimensions.cgSize.dividedByScreenScale().integralFloor diff --git a/submodules/Svg/BUCK b/submodules/Svg/BUCK new file mode 100644 index 0000000000..f7bcd103e0 --- /dev/null +++ b/submodules/Svg/BUCK @@ -0,0 +1,29 @@ +load("//Config:buck_rule_macros.bzl", "static_library") + +static_library( + name = "Svg", + srcs = glob([ + "Sources/**/*.m", + "Sources/**/*.mm", + "Sources/**/*.c", + "Sources/**/*.cpp", + ]), + compiler_flags = [ + "-DSVGKitLogVerbose(...)=1", + "-DSVGKitLogWarn(...)=1", + "-DSVGKitLogError(...)=1", + "-DSVGKitLogInfo(...)=1", + ], + headers = glob([ + "Sources/**/*.h", + ]), + exported_headers = glob([ + "Sources/*.h", + ]), + exported_preprocessor_flags = [ + "-I${SDKROOT}/usr/include/libxml2", + ], + frameworks = [ + "$SDKROOT/System/Library/Frameworks/libxml2.tbd", + ], +) diff --git a/submodules/Svg/Sources/Svg.h b/submodules/Svg/Sources/Svg.h new file mode 100755 index 0000000000..69063f40a5 --- /dev/null +++ b/submodules/Svg/Sources/Svg.h @@ -0,0 +1,9 @@ +#ifndef Lottie_h +#define Lottie_h + +#import +#import + +UIImage * _Nullable drawSvgImage(NSData * _Nonnull data, CGSize size); + +#endif /* Lottie_h */ diff --git a/submodules/Svg/Sources/Svg.m b/submodules/Svg/Sources/Svg.m new file mode 100755 index 0000000000..eace7feb50 --- /dev/null +++ b/submodules/Svg/Sources/Svg.m @@ -0,0 +1,35 @@ +#import "Svg.h" + +#import "SVGKit.h" +#import "SVGKExporterUIImage.h" + + +UIImage * _Nullable drawSvgImage(NSData * _Nonnull data, CGSize size) { + NSDate *startTime = [NSDate date]; + + SVGKImage *image = [[SVGKImage alloc] initWithData:data]; + if (image == nil) { + return; + } + + double deltaTime = -1.0f * [startTime timeIntervalSinceNow]; + //printf("parseTime = %f\n", deltaTime); + + UIGraphicsBeginImageContextWithOptions(size, true, 1.0); + + CGContextRef context = UIGraphicsGetCurrentContext(); + CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor); + CGContextFillRect(context, CGRectMake(0.0f, 0.0f, size.width, size.height)); + + startTime = [NSDate date]; + + [image renderToContext:context antiAliased:true curveFlatnessFactor:1.0 interpolationQuality:kCGInterpolationDefault flipYaxis:false]; + + deltaTime = -1.0f * [startTime timeIntervalSinceNow]; + //printf("drawingTime = %f\n", deltaTime); + + UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + + return resultImage; +} diff --git a/submodules/WallpaperResources/BUCK b/submodules/WallpaperResources/BUCK index c00518c487..c1aa1769d7 100644 --- a/submodules/WallpaperResources/BUCK +++ b/submodules/WallpaperResources/BUCK @@ -18,6 +18,7 @@ static_library( "//submodules/PhotoResources:PhotoResources", "//submodules/PersistentStringHash:PersistentStringHash", "//submodules/AppBundle:AppBundle", + "//submodules/Svg:Svg", ], frameworks = [ "$SDKROOT/System/Library/Frameworks/Foundation.framework", diff --git a/submodules/WallpaperResources/Sources/WallpaperResources.swift b/submodules/WallpaperResources/Sources/WallpaperResources.swift index 18d857c3d4..f44ef95be7 100644 --- a/submodules/WallpaperResources/Sources/WallpaperResources.swift +++ b/submodules/WallpaperResources/Sources/WallpaperResources.swift @@ -13,6 +13,7 @@ import LocalMediaResources import TelegramPresentationData import TelegramUIPreferences import AppBundle +import Svg public func wallpaperDatas(account: Account, accountManager: AccountManager, fileReference: FileMediaReference? = nil, representations: [ImageRepresentationWithReference], alwaysShowThumbnailFirst: Bool = false, thumbnail: Bool = false, onlyFullSize: Bool = false, autoFetchFullSize: Bool = false, synchronousLoad: Bool = false) -> Signal<(Data?, Data?, Bool), NoError> { if let smallestRepresentation = smallestImageRepresentation(representations.map({ $0.representation })), let largestRepresentation = largestImageRepresentation(representations.map({ $0.representation })), let smallestIndex = representations.firstIndex(where: { $0.representation == smallestRepresentation }), let largestIndex = representations.firstIndex(where: { $0.representation == largestRepresentation }) { @@ -193,11 +194,15 @@ public func wallpaperImage(account: Account, accountManager: AccountManager, fil var imageOrientation: UIImage.Orientation = .up if let fullSizeData = fullSizeData { if fullSizeComplete { - let options = NSMutableDictionary() - options[kCGImageSourceShouldCache as NSString] = false as NSNumber - if let imageSource = CGImageSourceCreateWithData(fullSizeData as CFData, nil), let image = CGImageSourceCreateImageAtIndex(imageSource, 0, options as CFDictionary) { - imageOrientation = imageOrientationFromSource(imageSource) - fullSizeImage = image + if fullSizeData.count > 5, let string = String(data: fullSizeData.subdata(in: 0 ..< 5), encoding: .utf8), string == "