-
Notifications
You must be signed in to change notification settings - Fork 1
/
PhotoResPreferenceController.m
executable file
·99 lines (88 loc) · 3.46 KB
/
PhotoResPreferenceController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#import <UIKit/UIKit.h>
#import <Cephei/HBListController.h>
#import <Cephei/HBAppearanceSettings.h>
#import <Social/Social.h>
#import <substrate.h>
#import "Common.h"
#import "../PSPrefs.x"
#import <dlfcn.h>
@interface PhotoResPreferenceController : HBListController
@end
static CGSize resolutionFromAVCaptureDeviceFormat(AVCaptureDeviceFormat *format){
CGSize res = CGSizeZero;
if (isiOS8Up) {
CMVideoDimensions dimension8 = format.highResolutionStillImageDimensions;
res = (CGSize){
dimension8.width, dimension8.height
};
} else if (isiOS7) {
CMVideoDimensions dimension7 = [format sensorDimensions];
res = (CGSize){
dimension7.width, dimension7.height
};
} else {
AVCaptureDeviceFormatInternal *internal6;
object_getInstanceVariable(format, "_internal", (void * *)&internal6);
NSDictionary *resDict6;
object_getInstanceVariable(internal6, "formatDictionary", (void * *)&resDict6);
res = (CGSize){
[resDict6[@"Width"] floatValue], [resDict6[@"Height"] floatValue]
};
}
return res;
}
static CGSize bestPhotoResolution(){
NSUInteger pixels = 0;
NSUInteger index = 0;
NSArray *formats = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo].formats;
for (AVCaptureDeviceFormat *format in formats) {
CGSize dimension = resolutionFromAVCaptureDeviceFormat(format);
NSUInteger eachPixels = dimension.width * dimension.height;
if (eachPixels > pixels) {
eachPixels = pixels;
index = [formats indexOfObject:format];
}
}
AVCaptureDeviceFormat *bestFormat = formats[index];
return resolutionFromAVCaptureDeviceFormat(bestFormat);
}
@implementation PhotoResPreferenceController
HavePrefs()
+ (NSString *)hb_specifierPlist {
return @"PhotoRes";
}
- (instancetype)init {
if (self == [super init]) {
HBAppearanceSettings *appearanceSettings = [[HBAppearanceSettings alloc] init];
appearanceSettings.tintColor = UIColor.magentaColor;
appearanceSettings.tableViewCellTextColor = UIColor.redColor;
self.hb_appearanceSettings = appearanceSettings;
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"♥️" style:UIBarButtonItemStylePlain target:self action:@selector(love)] autorelease];
}
return self;
}
- (void)love {
SLComposeViewController *twitter = [[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter] retain];
twitter.initialText = @"#PhotoRes by @PoomSmart is really awesome!";
[self.navigationController presentViewController:twitter animated:YES completion:nil];
[twitter release];
}
- (void)setResValue:(id)value specifier:(PSSpecifier *)spec {
NSUInteger val = [value intValue];
NSString *key = spec.properties[@"key"];
CGSize bestRes = bestPhotoResolution();
NSUInteger bestWidth = (NSUInteger)bestRes.width;
NSUInteger bestHeight = (NSUInteger)bestRes.height;
if ([key isEqualToString:widthKey]) {
if (val > bestWidth)
val = bestWidth;
} else if ([key isEqualToString:heightKey]) {
if (val > bestHeight)
val = bestHeight;
}
[self setPreferenceValue:@(val) specifier:spec];
[[NSUserDefaults standardUserDefaults] synchronize];
[self reloadSpecifier:spec animated:NO];
}
HaveBanner2(@"PhotoRes", UIColor.magentaColor, @"Photos at any size", UIColor.redColor)
@end