@tbvjaos510/react-native-paste-input 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.circleci/config.yml +130 -0
- package/LICENSE +21 -0
- package/README.md +73 -0
- package/android/.project +17 -0
- package/android/.settings/org.eclipse.buildship.core.prefs +13 -0
- package/android/build.gradle +94 -0
- package/android/generated/java/com/facebook/react/viewmanagers/PasteTextInputManagerDelegate.java +236 -0
- package/android/generated/java/com/facebook/react/viewmanagers/PasteTextInputManagerInterface.java +84 -0
- package/android/generated/jni/CMakeLists.txt +36 -0
- package/android/generated/jni/PasteTextInputSpecs-generated.cpp +27 -0
- package/android/generated/jni/PasteTextInputSpecs.h +28 -0
- package/android/generated/jni/react/renderer/components/PasteTextInputSpecs/ComponentDescriptors.cpp +22 -0
- package/android/generated/jni/react/renderer/components/PasteTextInputSpecs/ComponentDescriptors.h +166 -0
- package/android/generated/jni/react/renderer/components/PasteTextInputSpecs/EventEmitters.cpp +183 -0
- package/android/generated/jni/react/renderer/components/PasteTextInputSpecs/EventEmitters.h +148 -0
- package/android/generated/jni/react/renderer/components/PasteTextInputSpecs/PasteTextInputSpecsJSI-generated.cpp +17 -0
- package/android/generated/jni/react/renderer/components/PasteTextInputSpecs/PasteTextInputSpecsJSI.h +19 -0
- package/android/generated/jni/react/renderer/components/PasteTextInputSpecs/Props.cpp +640 -0
- package/android/generated/jni/react/renderer/components/PasteTextInputSpecs/Props.h +144 -0
- package/android/generated/jni/react/renderer/components/PasteTextInputSpecs/ShadowNodes.cpp +247 -0
- package/android/generated/jni/react/renderer/components/PasteTextInputSpecs/ShadowNodes.h +95 -0
- package/android/generated/jni/react/renderer/components/PasteTextInputSpecs/States.cpp +14 -0
- package/android/generated/jni/react/renderer/components/PasteTextInputSpecs/States.h +19 -0
- package/android/gradle.properties +6 -0
- package/android/src/main/java/com/mattermost/pasteinputtext/IPasteInputListener.kt +8 -0
- package/android/src/main/java/com/mattermost/pasteinputtext/PasteInputActionCallback.kt +72 -0
- package/android/src/main/java/com/mattermost/pasteinputtext/PasteInputEditText.kt +60 -0
- package/android/src/main/java/com/mattermost/pasteinputtext/PasteInputFileFromUrl.kt +50 -0
- package/android/src/main/java/com/mattermost/pasteinputtext/PasteInputListener.kt +84 -0
- package/android/src/main/java/com/mattermost/pasteinputtext/PasteTextInputManager.kt +72 -0
- package/android/src/main/java/com/mattermost/pasteinputtext/PasteTextInputPackage.kt +14 -0
- package/android/src/main/java/com/mattermost/pasteinputtext/PasteTextInputPasteEvent.java +41 -0
- package/android/src/main/java/com/mattermost/pasteinputtext/RealPathUtil.kt +174 -0
- package/ios/NSData+MimeType.h +20 -0
- package/ios/NSData+MimeType.m +59 -0
- package/ios/PasteInput-Bridging-Header.h +1 -0
- package/ios/PasteInput.xcodeproj/project.pbxproj +319 -0
- package/ios/PasteInputTextView.h +20 -0
- package/ios/PasteInputTextView.m +68 -0
- package/ios/PasteInputView.h +18 -0
- package/ios/PasteInputView.m +96 -0
- package/ios/PasteTextInput.h +13 -0
- package/ios/PasteTextInput.mm +726 -0
- package/ios/PasteTextInputManager.mm +171 -0
- package/ios/Swime/MimeType.h +70 -0
- package/ios/Swime/MimeType.m +701 -0
- package/ios/Swime/Swime.h +14 -0
- package/ios/Swime/Swime.m +28 -0
- package/ios/Swime/SwimeProxy.h +18 -0
- package/ios/Swime/SwimeProxy.m +66 -0
- package/ios/Swime/SwimeUtils.h +12 -0
- package/ios/Swime/SwimeUtils.m +23 -0
- package/ios/UIImage+ImageEffects.h +112 -0
- package/ios/UIImage+ImageEffects.m +310 -0
- package/ios/UIImage+vImageScaling.h +16 -0
- package/ios/UIImage+vImageScaling.m +48 -0
- package/ios/UIPasteboard+GetImageInfo.h +19 -0
- package/ios/UIPasteboard+GetImageInfo.m +98 -0
- package/ios/generated/PasteTextInputSpecs/ComponentDescriptors.cpp +22 -0
- package/ios/generated/PasteTextInputSpecs/ComponentDescriptors.h +42 -0
- package/ios/generated/PasteTextInputSpecs/EventEmitters.cpp +41 -0
- package/ios/generated/PasteTextInputSpecs/EventEmitters.h +37 -0
- package/ios/generated/PasteTextInputSpecs/PasteTextInputSpecs-generated.mm +16 -0
- package/ios/generated/PasteTextInputSpecs/PasteTextInputSpecs.h +38 -0
- package/ios/generated/PasteTextInputSpecs/Props.cpp +142 -0
- package/ios/generated/PasteTextInputSpecs/Props.h +81 -0
- package/ios/generated/PasteTextInputSpecs/RCTComponentViewHelpers.h +106 -0
- package/ios/generated/PasteTextInputSpecs/ShadowNodes.cpp +127 -0
- package/ios/generated/PasteTextInputSpecs/ShadowNodes.h +85 -0
- package/ios/generated/PasteTextInputSpecs/States.cpp +16 -0
- package/ios/generated/PasteTextInputSpecs/States.h +53 -0
- package/ios/generated/PasteTextInputSpecsJSI-generated.cpp +17 -0
- package/ios/generated/PasteTextInputSpecsJSI.h +19 -0
- package/lib/commonjs/PasteTextInput.js +446 -0
- package/lib/commonjs/PasteTextInput.js.map +1 -0
- package/lib/commonjs/PasteTextInputNativeComponent.ts +277 -0
- package/lib/commonjs/index.js +25 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/module.d.js +2 -0
- package/lib/commonjs/module.d.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/types.js +6 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/module/PasteTextInput.js +440 -0
- package/lib/module/PasteTextInput.js.map +1 -0
- package/lib/module/PasteTextInputNativeComponent.ts +277 -0
- package/lib/module/index.js +9 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/module.d.js +2 -0
- package/lib/module/module.d.js.map +1 -0
- package/lib/module/types.js +4 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/src/PasteTextInput.d.ts +5 -0
- package/lib/typescript/src/PasteTextInput.d.ts.map +1 -0
- package/lib/typescript/src/PasteTextInputNativeComponent.d.ts +168 -0
- package/lib/typescript/src/PasteTextInputNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +6 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +56 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/package.json +140 -0
- package/react-native-paste-input.podspec +20 -0
- package/react-native.config.js +13 -0
- package/src/PasteTextInput.tsx +615 -0
- package/src/PasteTextInputNativeComponent.ts +277 -0
- package/src/index.ts +13 -0
- package/src/module.d.ts +4 -0
- package/src/types.ts +71 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
#import "MimeType.h"
|
|
3
|
+
#import "SwimeUtils.h"
|
|
4
|
+
|
|
5
|
+
@interface Swime : NSObject
|
|
6
|
+
|
|
7
|
+
@property (nonatomic, readonly) NSData * _Nullable data;
|
|
8
|
+
@property (nonatomic, readonly) SwimeUtils * _Nullable utils;
|
|
9
|
+
|
|
10
|
+
+ (nullable MimeType *)mimeTypeWithData:(NSData *_Nullable)data;
|
|
11
|
+
+ (nullable MimeType *)mimeTypeWithBytes:(NSData *_Nullable)bytes;
|
|
12
|
+
+ (nullable MimeType *)mimeTypeWithSwime:(SwimeUtils *_Nullable)swime;
|
|
13
|
+
|
|
14
|
+
@end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#import "Swime.h"
|
|
2
|
+
|
|
3
|
+
@implementation Swime
|
|
4
|
+
|
|
5
|
+
+ (nullable MimeType *)mimeTypeWithData:(NSData *)data {
|
|
6
|
+
SwimeUtils *swime = [[SwimeUtils alloc] initWithData:data];
|
|
7
|
+
return [self mimeTypeWithSwime:swime];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
+ (nullable MimeType *)mimeTypeWithBytes:(NSData *)bytes {
|
|
11
|
+
SwimeUtils *swime = [[SwimeUtils alloc] initWithBytes:(NSUInteger *)bytes.bytes length:bytes.length];
|
|
12
|
+
return [self mimeTypeWithSwime:swime];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
+ (nullable MimeType *)mimeTypeWithSwime:(SwimeUtils *)swime {
|
|
16
|
+
NSUInteger count = MIN(swime.data.length, 262);
|
|
17
|
+
NSData *data = [swime readBytesWithCount:count];
|
|
18
|
+
|
|
19
|
+
for (MimeType *mime in MimeType.all) {
|
|
20
|
+
if ([mime matchesBytes:data swime:swime]) {
|
|
21
|
+
return mime;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return nil;
|
|
26
|
+
}
|
|
27
|
+
@end
|
|
28
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
|
|
3
|
+
@interface MimeTypeProxy : NSObject
|
|
4
|
+
|
|
5
|
+
@property (nonatomic, copy, readonly) NSString *mime;
|
|
6
|
+
@property (nonatomic, copy, readonly) NSString *ext;
|
|
7
|
+
|
|
8
|
+
- (instancetype)initWithMime:(NSString *)mime ext:(NSString *)ext;
|
|
9
|
+
|
|
10
|
+
@end
|
|
11
|
+
|
|
12
|
+
@interface SwimeProxy : NSObject
|
|
13
|
+
|
|
14
|
+
+ (instancetype)shared;
|
|
15
|
+
- (MimeTypeProxy *)getMimeFromUti:(NSString *)uti;
|
|
16
|
+
- (MimeTypeProxy *)getMimeAndExtension:(NSData *)data uti:(NSString *)uti;
|
|
17
|
+
|
|
18
|
+
@end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
//
|
|
2
|
+
// SwimeProxy.m
|
|
3
|
+
// Mattermost
|
|
4
|
+
//
|
|
5
|
+
// Created by Elias Nahum on 15-10-19.
|
|
6
|
+
// Copyright © 2019 Facebook. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#import "Swime.h"
|
|
10
|
+
#import "SwimeProxy.h"
|
|
11
|
+
|
|
12
|
+
@implementation MimeTypeProxy
|
|
13
|
+
|
|
14
|
+
- (instancetype)initWithMime:(NSString *)mime ext:(NSString *)ext {
|
|
15
|
+
self = [super init];
|
|
16
|
+
if (self) {
|
|
17
|
+
_mime = mime;
|
|
18
|
+
_ext = ext;
|
|
19
|
+
}
|
|
20
|
+
return self;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@end
|
|
24
|
+
|
|
25
|
+
@implementation SwimeProxy
|
|
26
|
+
|
|
27
|
+
+ (instancetype)shared {
|
|
28
|
+
static SwimeProxy *sharedInstance = nil;
|
|
29
|
+
static dispatch_once_t onceToken;
|
|
30
|
+
dispatch_once(&onceToken, ^{
|
|
31
|
+
sharedInstance = [[SwimeProxy alloc] init];
|
|
32
|
+
});
|
|
33
|
+
return sharedInstance;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
- (MimeTypeProxy *)getMimeFromUti:(NSString *)uti {
|
|
38
|
+
if ([uti isEqualToString:@"org.openxmlformats.openxml"]) {
|
|
39
|
+
return [[MimeTypeProxy alloc] initWithMime:@"application/xml" ext:@".xml"];
|
|
40
|
+
} else if ([uti isEqualToString:@"org.openxmlformats.wordprocessingml.document"]) {
|
|
41
|
+
return [[MimeTypeProxy alloc] initWithMime:@"application/vnd.openxmlformats-officedocument.wordprocessingml.document" ext:@".docx"];
|
|
42
|
+
} else if ([uti isEqualToString:@"org.openxmlformats.spreadsheetml.sheet"]) {
|
|
43
|
+
return [[MimeTypeProxy alloc] initWithMime:@"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ext:@".xlsx"];
|
|
44
|
+
} else if ([uti isEqualToString:@"org.openxmlformats.presentationml.presentation"]) {
|
|
45
|
+
return [[MimeTypeProxy alloc] initWithMime:@"application/vnd.openxmlformats-officedocument.presentationml.presentation" ext:@".pptx"];
|
|
46
|
+
} else {
|
|
47
|
+
return nil;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
- (MimeTypeProxy *)getMimeAndExtension:(NSData *)data uti:(NSString *)uti {
|
|
52
|
+
MimeTypeProxy *mime = [self getMimeFromUti:uti];
|
|
53
|
+
if (mime != nil) {
|
|
54
|
+
return mime;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
MimeType *proxy = [Swime mimeTypeWithData:data];
|
|
58
|
+
if (proxy) {
|
|
59
|
+
return [[MimeTypeProxy alloc] initWithMime:proxy.mime ext:proxy.ext];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return nil;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@end
|
|
66
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
|
|
3
|
+
@interface SwimeUtils : NSObject
|
|
4
|
+
|
|
5
|
+
@property (nonatomic, readonly) NSData * _Nullable data;
|
|
6
|
+
|
|
7
|
+
- (instancetype _Nullable )initWithData:(NSData *_Nullable)data;
|
|
8
|
+
- (instancetype _Nullable )initWithBytes:(NSUInteger *_Nullable)bytes length:(NSUInteger)length;
|
|
9
|
+
|
|
10
|
+
- (NSData *_Nullable)readBytesWithCount:(NSUInteger)count;
|
|
11
|
+
|
|
12
|
+
@end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#import "SwimeUtils.h"
|
|
2
|
+
|
|
3
|
+
@implementation SwimeUtils
|
|
4
|
+
|
|
5
|
+
- (instancetype)initWithData:(NSData *)data {
|
|
6
|
+
self = [super init];
|
|
7
|
+
if (self) {
|
|
8
|
+
_data = data;
|
|
9
|
+
}
|
|
10
|
+
return self;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
- (instancetype)initWithBytes:(NSUInteger *)bytes length:(NSUInteger)length {
|
|
14
|
+
NSData *data = [NSData dataWithBytes:bytes length:length];
|
|
15
|
+
return [self initWithData:data];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
- (NSData *)readBytesWithCount:(NSUInteger)count {
|
|
19
|
+
NSMutableData *bytes = [NSMutableData dataWithLength:count];
|
|
20
|
+
[self.data getBytes:bytes.mutableBytes length:count];
|
|
21
|
+
return bytes;
|
|
22
|
+
}
|
|
23
|
+
@end
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/*
|
|
2
|
+
File: UIImage+ImageEffects.h
|
|
3
|
+
Abstract: This is a category of UIImage that adds methods to apply blur and tint effects to an image. This is the code you’ll want to look out to find out how to use vImage to efficiently calculate a blur.
|
|
4
|
+
Version: 1.0
|
|
5
|
+
|
|
6
|
+
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
|
|
7
|
+
Inc. ("Apple") in consideration of your agreement to the following
|
|
8
|
+
terms, and your use, installation, modification or redistribution of
|
|
9
|
+
this Apple software constitutes acceptance of these terms. If you do
|
|
10
|
+
not agree with these terms, please do not use, install, modify or
|
|
11
|
+
redistribute this Apple software.
|
|
12
|
+
|
|
13
|
+
In consideration of your agreement to abide by the following terms, and
|
|
14
|
+
subject to these terms, Apple grants you a personal, non-exclusive
|
|
15
|
+
license, under Apple's copyrights in this original Apple software (the
|
|
16
|
+
"Apple Software"), to use, reproduce, modify and redistribute the Apple
|
|
17
|
+
Software, with or without modifications, in source and/or binary forms;
|
|
18
|
+
provided that if you redistribute the Apple Software in its entirety and
|
|
19
|
+
without modifications, you must retain this notice and the following
|
|
20
|
+
text and disclaimers in all such redistributions of the Apple Software.
|
|
21
|
+
Neither the name, trademarks, service marks or logos of Apple Inc. may
|
|
22
|
+
be used to endorse or promote products derived from the Apple Software
|
|
23
|
+
without specific prior written permission from Apple. Except as
|
|
24
|
+
expressly stated in this notice, no other rights or licenses, express or
|
|
25
|
+
implied, are granted by Apple herein, including but not limited to any
|
|
26
|
+
patent rights that may be infringed by your derivative works or by other
|
|
27
|
+
works in which the Apple Software may be incorporated.
|
|
28
|
+
|
|
29
|
+
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
|
|
30
|
+
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
|
|
31
|
+
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
|
|
32
|
+
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
|
|
33
|
+
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
|
|
34
|
+
|
|
35
|
+
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
|
|
36
|
+
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
37
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
38
|
+
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
|
|
39
|
+
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
|
|
40
|
+
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
|
|
41
|
+
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
|
|
42
|
+
POSSIBILITY OF SUCH DAMAGE.
|
|
43
|
+
|
|
44
|
+
Copyright (C) 2013 Apple Inc. All Rights Reserved.
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
Copyright © 2013 Apple Inc. All rights reserved.
|
|
48
|
+
WWDC 2013 License
|
|
49
|
+
|
|
50
|
+
NOTE: This Apple Software was supplied by Apple as part of a WWDC 2013
|
|
51
|
+
Session. Please refer to the applicable WWDC 2013 Session for further
|
|
52
|
+
information.
|
|
53
|
+
|
|
54
|
+
IMPORTANT: This Apple software is supplied to you by Apple Inc.
|
|
55
|
+
("Apple") in consideration of your agreement to the following terms, and
|
|
56
|
+
your use, installation, modification or redistribution of this Apple
|
|
57
|
+
software constitutes acceptance of these terms. If you do not agree with
|
|
58
|
+
these terms, please do not use, install, modify or redistribute this
|
|
59
|
+
Apple software.
|
|
60
|
+
|
|
61
|
+
In consideration of your agreement to abide by the following terms, and
|
|
62
|
+
subject to these terms, Apple grants you a non-exclusive license, under
|
|
63
|
+
Apple's copyrights in this original Apple software (the "Apple
|
|
64
|
+
Software"), to use, reproduce, modify and redistribute the Apple
|
|
65
|
+
Software, with or without modifications, in source and/or binary forms;
|
|
66
|
+
provided that if you redistribute the Apple Software in its entirety and
|
|
67
|
+
without modifications, you must retain this notice and the following
|
|
68
|
+
text and disclaimers in all such redistributions of the Apple Software.
|
|
69
|
+
Neither the name, trademarks, service marks or logos of Apple Inc. may
|
|
70
|
+
be used to endorse or promote products derived from the Apple Software
|
|
71
|
+
without specific prior written permission from Apple. Except as
|
|
72
|
+
expressly stated in this notice, no other rights or licenses, express or
|
|
73
|
+
implied, are granted by Apple herein, including but not limited to any
|
|
74
|
+
patent rights that may be infringed by your derivative works or by other
|
|
75
|
+
works in which the Apple Software may be incorporated.
|
|
76
|
+
|
|
77
|
+
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES
|
|
78
|
+
NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE
|
|
79
|
+
IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR
|
|
80
|
+
A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
|
|
81
|
+
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
|
|
82
|
+
|
|
83
|
+
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
|
|
84
|
+
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
85
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
86
|
+
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
|
|
87
|
+
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
|
|
88
|
+
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
|
|
89
|
+
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
|
|
90
|
+
POSSIBILITY OF SUCH DAMAGE.
|
|
91
|
+
|
|
92
|
+
EA1002
|
|
93
|
+
5/3/2013
|
|
94
|
+
*/
|
|
95
|
+
|
|
96
|
+
@import UIKit;
|
|
97
|
+
|
|
98
|
+
@interface UIImage (ImageEffects)
|
|
99
|
+
|
|
100
|
+
- (UIImage *)applyLightEffect;
|
|
101
|
+
- (UIImage *)applyExtraLightEffect;
|
|
102
|
+
- (UIImage *)applyDarkEffect;
|
|
103
|
+
- (UIImage *)applyTintEffectWithColor:(UIColor *)tintColor;
|
|
104
|
+
|
|
105
|
+
- (UIImage *)applyBlurWithRadius:(CGFloat)blurRadius tintColor:(UIColor *)tintColor saturationDeltaFactor:(CGFloat)saturationDeltaFactor maskImage:(UIImage *)maskImage;
|
|
106
|
+
|
|
107
|
+
- (UIImage *)rotateByDegrees:(CGFloat)degrees;
|
|
108
|
+
|
|
109
|
+
+ (UIImage *)imagePixelFromColor:(UIColor *)color;
|
|
110
|
+
+ (UIImage *)imageFromColor:(UIColor *)color withSize:(CGSize)size;
|
|
111
|
+
|
|
112
|
+
@end
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
/*
|
|
2
|
+
File: UIImage+ImageEffects.m
|
|
3
|
+
Abstract: This is a category of UIImage that adds methods to apply blur and tint effects to an image. This is the code you’ll want to look out to find out how to use vImage to efficiently calculate a blur.
|
|
4
|
+
Version: 1.0
|
|
5
|
+
|
|
6
|
+
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
|
|
7
|
+
Inc. ("Apple") in consideration of your agreement to the following
|
|
8
|
+
terms, and your use, installation, modification or redistribution of
|
|
9
|
+
this Apple software constitutes acceptance of these terms. If you do
|
|
10
|
+
not agree with these terms, please do not use, install, modify or
|
|
11
|
+
redistribute this Apple software.
|
|
12
|
+
|
|
13
|
+
In consideration of your agreement to abide by the following terms, and
|
|
14
|
+
subject to these terms, Apple grants you a personal, non-exclusive
|
|
15
|
+
license, under Apple's copyrights in this original Apple software (the
|
|
16
|
+
"Apple Software"), to use, reproduce, modify and redistribute the Apple
|
|
17
|
+
Software, with or without modifications, in source and/or binary forms;
|
|
18
|
+
provided that if you redistribute the Apple Software in its entirety and
|
|
19
|
+
without modifications, you must retain this notice and the following
|
|
20
|
+
text and disclaimers in all such redistributions of the Apple Software.
|
|
21
|
+
Neither the name, trademarks, service marks or logos of Apple Inc. may
|
|
22
|
+
be used to endorse or promote products derived from the Apple Software
|
|
23
|
+
without specific prior written permission from Apple. Except as
|
|
24
|
+
expressly stated in this notice, no other rights or licenses, express or
|
|
25
|
+
implied, are granted by Apple herein, including but not limited to any
|
|
26
|
+
patent rights that may be infringed by your derivative works or by other
|
|
27
|
+
works in which the Apple Software may be incorporated.
|
|
28
|
+
|
|
29
|
+
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
|
|
30
|
+
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
|
|
31
|
+
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
|
|
32
|
+
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
|
|
33
|
+
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
|
|
34
|
+
|
|
35
|
+
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
|
|
36
|
+
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
37
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
38
|
+
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
|
|
39
|
+
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
|
|
40
|
+
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
|
|
41
|
+
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
|
|
42
|
+
POSSIBILITY OF SUCH DAMAGE.
|
|
43
|
+
|
|
44
|
+
Copyright (C) 2013 Apple Inc. All Rights Reserved.
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
Copyright © 2013 Apple Inc. All rights reserved.
|
|
48
|
+
WWDC 2013 License
|
|
49
|
+
|
|
50
|
+
NOTE: This Apple Software was supplied by Apple as part of a WWDC 2013
|
|
51
|
+
Session. Please refer to the applicable WWDC 2013 Session for further
|
|
52
|
+
information.
|
|
53
|
+
|
|
54
|
+
IMPORTANT: This Apple software is supplied to you by Apple Inc.
|
|
55
|
+
("Apple") in consideration of your agreement to the following terms, and
|
|
56
|
+
your use, installation, modification or redistribution of this Apple
|
|
57
|
+
software constitutes acceptance of these terms. If you do not agree with
|
|
58
|
+
these terms, please do not use, install, modify or redistribute this
|
|
59
|
+
Apple software.
|
|
60
|
+
|
|
61
|
+
In consideration of your agreement to abide by the following terms, and
|
|
62
|
+
subject to these terms, Apple grants you a non-exclusive license, under
|
|
63
|
+
Apple's copyrights in this original Apple software (the "Apple
|
|
64
|
+
Software"), to use, reproduce, modify and redistribute the Apple
|
|
65
|
+
Software, with or without modifications, in source and/or binary forms;
|
|
66
|
+
provided that if you redistribute the Apple Software in its entirety and
|
|
67
|
+
without modifications, you must retain this notice and the following
|
|
68
|
+
text and disclaimers in all such redistributions of the Apple Software.
|
|
69
|
+
Neither the name, trademarks, service marks or logos of Apple Inc. may
|
|
70
|
+
be used to endorse or promote products derived from the Apple Software
|
|
71
|
+
without specific prior written permission from Apple. Except as
|
|
72
|
+
expressly stated in this notice, no other rights or licenses, express or
|
|
73
|
+
implied, are granted by Apple herein, including but not limited to any
|
|
74
|
+
patent rights that may be infringed by your derivative works or by other
|
|
75
|
+
works in which the Apple Software may be incorporated.
|
|
76
|
+
|
|
77
|
+
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES
|
|
78
|
+
NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE
|
|
79
|
+
IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR
|
|
80
|
+
A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
|
|
81
|
+
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
|
|
82
|
+
|
|
83
|
+
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
|
|
84
|
+
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
85
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
86
|
+
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
|
|
87
|
+
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
|
|
88
|
+
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
|
|
89
|
+
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
|
|
90
|
+
POSSIBILITY OF SUCH DAMAGE.
|
|
91
|
+
|
|
92
|
+
EA1002
|
|
93
|
+
5/3/2013
|
|
94
|
+
*/
|
|
95
|
+
|
|
96
|
+
#import "UIImage+ImageEffects.h"
|
|
97
|
+
|
|
98
|
+
@import Accelerate;
|
|
99
|
+
#import <float.h>
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
@implementation UIImage (ImageEffects)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
- (UIImage *)applyLightEffect
|
|
106
|
+
{
|
|
107
|
+
UIColor *tintColor = [UIColor colorWithWhite:1.0 alpha:0.3];
|
|
108
|
+
return [self applyBlurWithRadius:30 tintColor:tintColor saturationDeltaFactor:1.8 maskImage:nil];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
- (UIImage *)applyExtraLightEffect
|
|
113
|
+
{
|
|
114
|
+
UIColor *tintColor = [UIColor colorWithWhite:0.97 alpha:0.82];
|
|
115
|
+
return [self applyBlurWithRadius:20 tintColor:tintColor saturationDeltaFactor:1.8 maskImage:nil];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
- (UIImage *)applyDarkEffect
|
|
120
|
+
{
|
|
121
|
+
UIColor *tintColor = [UIColor colorWithWhite:0.11 alpha:0.73];
|
|
122
|
+
return [self applyBlurWithRadius:20 tintColor:tintColor saturationDeltaFactor:1.8 maskImage:nil];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
- (UIImage *)applyTintEffectWithColor:(UIColor *)tintColor
|
|
127
|
+
{
|
|
128
|
+
const CGFloat EffectColorAlpha = 0.6;
|
|
129
|
+
UIColor *effectColor = tintColor;
|
|
130
|
+
int componentCount = CGColorGetNumberOfComponents(tintColor.CGColor);
|
|
131
|
+
if (componentCount == 2) {
|
|
132
|
+
CGFloat b;
|
|
133
|
+
if ([tintColor getWhite:&b alpha:NULL]) {
|
|
134
|
+
effectColor = [UIColor colorWithWhite:b alpha:EffectColorAlpha];
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
CGFloat r, g, b;
|
|
139
|
+
if ([tintColor getRed:&r green:&g blue:&b alpha:NULL]) {
|
|
140
|
+
effectColor = [UIColor colorWithRed:r green:g blue:b alpha:EffectColorAlpha];
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return [self applyBlurWithRadius:10 tintColor:effectColor saturationDeltaFactor:-1.0 maskImage:nil];
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
- (UIImage *)applyBlurWithRadius:(CGFloat)blurRadius tintColor:(UIColor *)tintColor saturationDeltaFactor:(CGFloat)saturationDeltaFactor maskImage:(UIImage *)maskImage
|
|
148
|
+
{
|
|
149
|
+
// Check pre-conditions.
|
|
150
|
+
if (self.size.width < 1 || self.size.height < 1) {
|
|
151
|
+
NSLog (@"*** error: invalid size: (%.2f x %.2f). Both dimensions must be >= 1: %@", self.size.width, self.size.height, self);
|
|
152
|
+
return nil;
|
|
153
|
+
}
|
|
154
|
+
if (!self.CGImage) {
|
|
155
|
+
NSLog (@"*** error: image must be backed by a CGImage: %@", self);
|
|
156
|
+
return nil;
|
|
157
|
+
}
|
|
158
|
+
if (maskImage && !maskImage.CGImage) {
|
|
159
|
+
NSLog (@"*** error: maskImage must be backed by a CGImage: %@", maskImage);
|
|
160
|
+
return nil;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
CGRect imageRect = { CGPointZero, self.size };
|
|
164
|
+
UIImage *effectImage = self;
|
|
165
|
+
|
|
166
|
+
BOOL hasBlur = blurRadius > __FLT_EPSILON__;
|
|
167
|
+
BOOL hasSaturationChange = fabs(saturationDeltaFactor - 1.) > __FLT_EPSILON__;
|
|
168
|
+
if (hasBlur || hasSaturationChange) {
|
|
169
|
+
UIGraphicsBeginImageContextWithOptions(self.size, NO, [[UIScreen mainScreen] scale]);
|
|
170
|
+
CGContextRef effectInContext = UIGraphicsGetCurrentContext();
|
|
171
|
+
CGContextScaleCTM(effectInContext, 1.0, -1.0);
|
|
172
|
+
CGContextTranslateCTM(effectInContext, 0, -self.size.height);
|
|
173
|
+
CGContextDrawImage(effectInContext, imageRect, self.CGImage);
|
|
174
|
+
|
|
175
|
+
vImage_Buffer effectInBuffer;
|
|
176
|
+
effectInBuffer.data = CGBitmapContextGetData(effectInContext);
|
|
177
|
+
effectInBuffer.width = CGBitmapContextGetWidth(effectInContext);
|
|
178
|
+
effectInBuffer.height = CGBitmapContextGetHeight(effectInContext);
|
|
179
|
+
effectInBuffer.rowBytes = CGBitmapContextGetBytesPerRow(effectInContext);
|
|
180
|
+
|
|
181
|
+
UIGraphicsBeginImageContextWithOptions(self.size, NO, [[UIScreen mainScreen] scale]);
|
|
182
|
+
CGContextRef effectOutContext = UIGraphicsGetCurrentContext();
|
|
183
|
+
vImage_Buffer effectOutBuffer;
|
|
184
|
+
effectOutBuffer.data = CGBitmapContextGetData(effectOutContext);
|
|
185
|
+
effectOutBuffer.width = CGBitmapContextGetWidth(effectOutContext);
|
|
186
|
+
effectOutBuffer.height = CGBitmapContextGetHeight(effectOutContext);
|
|
187
|
+
effectOutBuffer.rowBytes = CGBitmapContextGetBytesPerRow(effectOutContext);
|
|
188
|
+
|
|
189
|
+
if (hasBlur) {
|
|
190
|
+
// A description of how to compute the box kernel width from the Gaussian
|
|
191
|
+
// radius (aka standard deviation) appears in the SVG spec:
|
|
192
|
+
// http://www.w3.org/TR/SVG/filters.html#feGaussianBlurElement
|
|
193
|
+
//
|
|
194
|
+
// For larger values of 's' (s >= 2.0), an approximation can be used: Three
|
|
195
|
+
// successive box-blurs build a piece-wise quadratic convolution kernel, which
|
|
196
|
+
// approximates the Gaussian kernel to within roughly 3%.
|
|
197
|
+
//
|
|
198
|
+
// let d = floor(s * 3*sqrt(2*pi)/4 + 0.5)
|
|
199
|
+
//
|
|
200
|
+
// ... if d is odd, use three box-blurs of size 'd', centered on the output pixel.
|
|
201
|
+
//
|
|
202
|
+
CGFloat inputRadius = blurRadius * [[UIScreen mainScreen] scale];
|
|
203
|
+
NSUInteger radius = floor(inputRadius * 3. * sqrt(2 * M_PI) / 4 + 0.5);
|
|
204
|
+
if (radius % 2 != 1) {
|
|
205
|
+
radius += 1; // force radius to be odd so that the three box-blur methodology works.
|
|
206
|
+
}
|
|
207
|
+
vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, NULL, 0, 0, radius, radius, 0, kvImageEdgeExtend);
|
|
208
|
+
vImageBoxConvolve_ARGB8888(&effectOutBuffer, &effectInBuffer, NULL, 0, 0, radius, radius, 0, kvImageEdgeExtend);
|
|
209
|
+
vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, NULL, 0, 0, radius, radius, 0, kvImageEdgeExtend);
|
|
210
|
+
}
|
|
211
|
+
BOOL effectImageBuffersAreSwapped = NO;
|
|
212
|
+
if (hasSaturationChange) {
|
|
213
|
+
CGFloat s = saturationDeltaFactor;
|
|
214
|
+
CGFloat floatingPointSaturationMatrix[] = {
|
|
215
|
+
0.0722 + 0.9278 * s, 0.0722 - 0.0722 * s, 0.0722 - 0.0722 * s, 0,
|
|
216
|
+
0.7152 - 0.7152 * s, 0.7152 + 0.2848 * s, 0.7152 - 0.7152 * s, 0,
|
|
217
|
+
0.2126 - 0.2126 * s, 0.2126 - 0.2126 * s, 0.2126 + 0.7873 * s, 0,
|
|
218
|
+
0, 0, 0, 1,
|
|
219
|
+
};
|
|
220
|
+
const int32_t divisor = 256;
|
|
221
|
+
NSUInteger matrixSize = sizeof(floatingPointSaturationMatrix)/sizeof(floatingPointSaturationMatrix[0]);
|
|
222
|
+
int16_t saturationMatrix[matrixSize];
|
|
223
|
+
for (NSUInteger i = 0; i < matrixSize; ++i) {
|
|
224
|
+
saturationMatrix[i] = (int16_t)roundf(floatingPointSaturationMatrix[i] * divisor);
|
|
225
|
+
}
|
|
226
|
+
if (hasBlur) {
|
|
227
|
+
vImageMatrixMultiply_ARGB8888(&effectOutBuffer, &effectInBuffer, saturationMatrix, divisor, NULL, NULL, kvImageNoFlags);
|
|
228
|
+
effectImageBuffersAreSwapped = YES;
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
vImageMatrixMultiply_ARGB8888(&effectInBuffer, &effectOutBuffer, saturationMatrix, divisor, NULL, NULL, kvImageNoFlags);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (!effectImageBuffersAreSwapped)
|
|
235
|
+
effectImage = UIGraphicsGetImageFromCurrentImageContext();
|
|
236
|
+
UIGraphicsEndImageContext();
|
|
237
|
+
|
|
238
|
+
if (effectImageBuffersAreSwapped)
|
|
239
|
+
effectImage = UIGraphicsGetImageFromCurrentImageContext();
|
|
240
|
+
UIGraphicsEndImageContext();
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// Set up output context.
|
|
244
|
+
UIGraphicsBeginImageContextWithOptions(self.size, NO, [[UIScreen mainScreen] scale]);
|
|
245
|
+
CGContextRef outputContext = UIGraphicsGetCurrentContext();
|
|
246
|
+
CGContextScaleCTM(outputContext, 1.0, -1.0);
|
|
247
|
+
CGContextTranslateCTM(outputContext, 0, -self.size.height);
|
|
248
|
+
|
|
249
|
+
// Draw base image.
|
|
250
|
+
CGContextDrawImage(outputContext, imageRect, self.CGImage);
|
|
251
|
+
|
|
252
|
+
// Draw effect image.
|
|
253
|
+
if (hasBlur) {
|
|
254
|
+
CGContextSaveGState(outputContext);
|
|
255
|
+
if (maskImage) {
|
|
256
|
+
CGContextClipToMask(outputContext, imageRect, maskImage.CGImage);
|
|
257
|
+
}
|
|
258
|
+
CGContextDrawImage(outputContext, imageRect, effectImage.CGImage);
|
|
259
|
+
CGContextRestoreGState(outputContext);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// Add in color tint.
|
|
263
|
+
if (tintColor) {
|
|
264
|
+
CGContextSaveGState(outputContext);
|
|
265
|
+
CGContextSetFillColorWithColor(outputContext, tintColor.CGColor);
|
|
266
|
+
CGContextFillRect(outputContext, imageRect);
|
|
267
|
+
CGContextRestoreGState(outputContext);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// Output image is ready.
|
|
271
|
+
UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();
|
|
272
|
+
UIGraphicsEndImageContext();
|
|
273
|
+
|
|
274
|
+
return outputImage;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
- (UIImage *)rotateByDegrees:(CGFloat)degrees {
|
|
278
|
+
UIView *rotatedViewBox = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.size.width, self.size.height)];
|
|
279
|
+
CGAffineTransform t = CGAffineTransformMakeRotation(degrees * M_PI / 180.0f);
|
|
280
|
+
rotatedViewBox.transform = t;
|
|
281
|
+
CGSize rotatedSize = rotatedViewBox.frame.size;
|
|
282
|
+
|
|
283
|
+
UIGraphicsBeginImageContext(rotatedSize);
|
|
284
|
+
CGContextRef bitmap = UIGraphicsGetCurrentContext();
|
|
285
|
+
CGContextTranslateCTM(bitmap, rotatedSize.width/2, rotatedSize.height/2);
|
|
286
|
+
CGContextRotateCTM(bitmap, degrees * M_PI / 180.0f);
|
|
287
|
+
CGContextScaleCTM(bitmap, 1.0, -1.0);
|
|
288
|
+
CGContextDrawImage(bitmap, CGRectMake(-self.size.width / 2, -self.size.height / 2, self.size.width, self.size.height), self.CGImage);
|
|
289
|
+
|
|
290
|
+
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
|
|
291
|
+
UIGraphicsEndImageContext();
|
|
292
|
+
return newImage;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
+ (UIImage *)imagePixelFromColor:(UIColor *)color {
|
|
296
|
+
return [UIImage imageFromColor:color withSize:CGSizeMake(1.0f, 1.0f)];
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
+ (UIImage *)imageFromColor:(UIColor *)color withSize:(CGSize)size {
|
|
300
|
+
CGRect rect = CGRectMake(0.0f, 0.0f, size.width, size.height);
|
|
301
|
+
UIGraphicsBeginImageContext(rect.size);
|
|
302
|
+
CGContextRef context = UIGraphicsGetCurrentContext();
|
|
303
|
+
CGContextSetFillColorWithColor(context, [color CGColor]);
|
|
304
|
+
CGContextFillRect(context, rect);
|
|
305
|
+
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
|
|
306
|
+
UIGraphicsEndImageContext();
|
|
307
|
+
return image;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
@end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//
|
|
2
|
+
// UIImage+vImageScaling.h
|
|
3
|
+
// UIImage+vImageScaling
|
|
4
|
+
//
|
|
5
|
+
// Created by Matt Donnelly on 03/07/2013.
|
|
6
|
+
// Copyright (c) 2013 Matt Donnelly. All rights reserved.
|
|
7
|
+
// taken from https://gist.github.com/mattdonnelly/5924492
|
|
8
|
+
|
|
9
|
+
#import <UIKit/UIKit.h>
|
|
10
|
+
|
|
11
|
+
@interface UIImage (vImageScaling)
|
|
12
|
+
|
|
13
|
+
- (UIImage *)vImageScaledImageWithSize:(CGSize)destSize;
|
|
14
|
+
- (UIImage *)vImageScaledImageWithSize:(CGSize)destSize contentMode:(UIViewContentMode)contentMode;
|
|
15
|
+
|
|
16
|
+
@end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
//
|
|
2
|
+
// UIImage+vImageScaling.m
|
|
3
|
+
// UIImage+vImageScaling
|
|
4
|
+
//
|
|
5
|
+
// Created by Matt Donnelly on 03/07/2013.
|
|
6
|
+
// Copyright (c) 2013 Matt Donnelly. All rights reserved.
|
|
7
|
+
// originally taken from https://gist.github.com/mattdonnelly/5924492
|
|
8
|
+
|
|
9
|
+
#import <Accelerate/Accelerate.h>
|
|
10
|
+
#import <UIKit/UIKit.h>
|
|
11
|
+
|
|
12
|
+
@implementation UIImage (vImageScaling)
|
|
13
|
+
|
|
14
|
+
- (UIImage *)vImageScaledImageWithSize:(CGSize)destSize {
|
|
15
|
+
UIGraphicsBeginImageContext(CGSizeMake(destSize.width, destSize.height));
|
|
16
|
+
[self drawInRect:CGRectMake(0, 0, destSize.width, destSize.height)];
|
|
17
|
+
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
|
|
18
|
+
UIGraphicsEndImageContext();
|
|
19
|
+
return newImage;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
- (UIImage *)vImageScaledImageWithSize:(CGSize)destSize contentMode:(UIViewContentMode)contentMode {
|
|
23
|
+
CGImageRef sourceRef = [self CGImage];
|
|
24
|
+
NSUInteger sourceWidth = CGImageGetWidth(sourceRef);
|
|
25
|
+
NSUInteger sourceHeight = CGImageGetHeight(sourceRef);
|
|
26
|
+
CGFloat horizontalRatio = destSize.width / sourceWidth;
|
|
27
|
+
CGFloat verticalRatio = destSize.height / sourceHeight;
|
|
28
|
+
CGFloat ratio;
|
|
29
|
+
|
|
30
|
+
switch (contentMode) {
|
|
31
|
+
case UIViewContentModeScaleAspectFill:
|
|
32
|
+
ratio = MAX(horizontalRatio, verticalRatio);
|
|
33
|
+
break;
|
|
34
|
+
|
|
35
|
+
case UIViewContentModeScaleAspectFit:
|
|
36
|
+
ratio = MIN(horizontalRatio, verticalRatio);
|
|
37
|
+
break;
|
|
38
|
+
|
|
39
|
+
default:
|
|
40
|
+
[NSException raise:NSInvalidArgumentException format:@"Unsupported content mode: %d", contentMode];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
CGSize newSize = CGSizeMake(sourceWidth * ratio, sourceHeight * ratio);
|
|
44
|
+
|
|
45
|
+
return [self vImageScaledImageWithSize:newSize];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//
|
|
2
|
+
// UIPasteboard+GetImageInfo.h
|
|
3
|
+
// Mattermost
|
|
4
|
+
//
|
|
5
|
+
// Created by Tek Min Ewe on 05/08/2019.
|
|
6
|
+
// Copyright © 2019 Facebook. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#import <UIKit/UIKit.h>
|
|
10
|
+
|
|
11
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
12
|
+
|
|
13
|
+
@interface UIPasteboard (GetImageInfo)
|
|
14
|
+
|
|
15
|
+
-(NSArray<NSDictionary *> *)getCopiedFiles;
|
|
16
|
+
|
|
17
|
+
@end
|
|
18
|
+
|
|
19
|
+
NS_ASSUME_NONNULL_END
|