-
Notifications
You must be signed in to change notification settings - Fork 511
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create example data to show failing un-rotation of baked orientation …
…in pixel data
- Loading branch information
1 parent
543c2bc
commit 8fb0458
Showing
8 changed files
with
240 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// ImageSource.h | ||
// Example | ||
// | ||
// Created by Alex Quinlivan on 16/04/21. | ||
// Copyright © 2021 Garrett Moon. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@protocol ImageSource <NSObject> | ||
|
||
@property (nonatomic, strong) NSURL *imageURL; | ||
@property (nonatomic, strong) id dominantColor; | ||
@property (nonatomic, assign) CGSize imageSize; | ||
|
||
+ (void)fetchImagesForWidth:(CGFloat)width completion:(void (^)(NSArray *images))completion; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// Oriented.h | ||
// Example | ||
// | ||
// Created by Alex Quinlivan on 16/04/21. | ||
// Copyright © 2021 Garrett Moon. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED | ||
#import <UIKit/UIKit.h> | ||
#else | ||
#import <Cocoa/Cocoa.h> | ||
#endif | ||
|
||
#import "ImageSource.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface Oriented : NSObject <ImageSource> | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
// | ||
// Oriented.m | ||
// Example | ||
// | ||
// Created by Alex Quinlivan on 16/04/21. | ||
// Copyright © 2021 Garrett Moon. All rights reserved. | ||
// | ||
|
||
#import "Oriented.h" | ||
|
||
#ifdef __MAC_OS_X_VERSION_MIN_REQUIRED | ||
|
||
@interface NSValue (PINiOSMapping) | ||
+ (NSValue *)valueWithCGSize:(CGSize)size; | ||
- (CGSize)CGSizeValue; | ||
@end | ||
|
||
@implementation NSValue (PINiOSMapping) | ||
|
||
+ (NSValue *)valueWithCGSize:(CGSize)size | ||
{ | ||
return [self valueWithSize:size]; | ||
} | ||
|
||
- (CGSize)CGSizeValue | ||
{ | ||
return self.sizeValue; | ||
} | ||
|
||
@end | ||
|
||
#endif | ||
|
||
@implementation Oriented | ||
@synthesize imageURL; | ||
@synthesize dominantColor; | ||
@synthesize imageSize; | ||
|
||
+ (void)fetchImagesForWidth:(CGFloat)width completion:(void (^)(NSArray *images))completion | ||
{ | ||
NSArray *orientedURLs = @[[NSURL URLWithString:@"https://github.com/AlexQuinlivan/exif-orientation-examples/blob/master/Landscape_0.jpg?raw=true"], | ||
[NSURL URLWithString:@"https://github.com/AlexQuinlivan/exif-orientation-examples/blob/master/Landscape_1.jpg?raw=true"], | ||
[NSURL URLWithString:@"https://github.com/AlexQuinlivan/exif-orientation-examples/blob/master/Landscape_2.jpg?raw=true"], | ||
[NSURL URLWithString:@"https://github.com/AlexQuinlivan/exif-orientation-examples/blob/master/Landscape_3.jpg?raw=true"], | ||
[NSURL URLWithString:@"https://github.com/AlexQuinlivan/exif-orientation-examples/blob/master/Landscape_4.jpg?raw=true"], | ||
[NSURL URLWithString:@"https://github.com/AlexQuinlivan/exif-orientation-examples/blob/master/Landscape_5.jpg?raw=true"], | ||
[NSURL URLWithString:@"https://github.com/AlexQuinlivan/exif-orientation-examples/blob/master/Landscape_6.jpg?raw=true"], | ||
[NSURL URLWithString:@"https://github.com/AlexQuinlivan/exif-orientation-examples/blob/master/Landscape_7.jpg?raw=true"], | ||
[NSURL URLWithString:@"https://github.com/AlexQuinlivan/exif-orientation-examples/blob/master/Landscape_8.jpg?raw=true"], | ||
[NSURL URLWithString:@"https://github.com/AlexQuinlivan/exif-orientation-examples/blob/master/Portrait_0.jpg?raw=true"], | ||
[NSURL URLWithString:@"https://github.com/AlexQuinlivan/exif-orientation-examples/blob/master/Portrait_1.jpg?raw=true"], | ||
[NSURL URLWithString:@"https://github.com/AlexQuinlivan/exif-orientation-examples/blob/master/Portrait_2.jpg?raw=true"], | ||
[NSURL URLWithString:@"https://github.com/AlexQuinlivan/exif-orientation-examples/blob/master/Portrait_3.jpg?raw=true"], | ||
[NSURL URLWithString:@"https://github.com/AlexQuinlivan/exif-orientation-examples/blob/master/Portrait_4.jpg?raw=true"], | ||
[NSURL URLWithString:@"https://github.com/AlexQuinlivan/exif-orientation-examples/blob/master/Portrait_5.jpg?raw=true"], | ||
[NSURL URLWithString:@"https://github.com/AlexQuinlivan/exif-orientation-examples/blob/master/Portrait_6.jpg?raw=true"], | ||
[NSURL URLWithString:@"https://github.com/AlexQuinlivan/exif-orientation-examples/blob/master/Portrait_7.jpg?raw=true"], | ||
[NSURL URLWithString:@"https://github.com/AlexQuinlivan/exif-orientation-examples/blob/master/Portrait_8.jpg?raw=true"], | ||
]; | ||
|
||
NSArray *orientedSizes = @[[NSValue valueWithCGSize:CGSizeMake(450, 300)], | ||
[NSValue valueWithCGSize:CGSizeMake(450, 300)], | ||
[NSValue valueWithCGSize:CGSizeMake(450, 300)], | ||
[NSValue valueWithCGSize:CGSizeMake(450, 300)], | ||
[NSValue valueWithCGSize:CGSizeMake(450, 300)], | ||
[NSValue valueWithCGSize:CGSizeMake(450, 300)], | ||
[NSValue valueWithCGSize:CGSizeMake(450, 300)], | ||
[NSValue valueWithCGSize:CGSizeMake(450, 300)], | ||
[NSValue valueWithCGSize:CGSizeMake(450, 300)], | ||
[NSValue valueWithCGSize:CGSizeMake(300, 450)], | ||
[NSValue valueWithCGSize:CGSizeMake(300, 450)], | ||
[NSValue valueWithCGSize:CGSizeMake(300, 450)], | ||
[NSValue valueWithCGSize:CGSizeMake(300, 450)], | ||
[NSValue valueWithCGSize:CGSizeMake(300, 450)], | ||
[NSValue valueWithCGSize:CGSizeMake(300, 450)], | ||
[NSValue valueWithCGSize:CGSizeMake(300, 450)], | ||
[NSValue valueWithCGSize:CGSizeMake(300, 450)], | ||
[NSValue valueWithCGSize:CGSizeMake(300, 450)], | ||
]; | ||
|
||
dispatch_group_t group = dispatch_group_create(); | ||
NSMutableArray *orienteds = [[NSMutableArray alloc] init]; | ||
|
||
CGFloat scale = 1; | ||
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED | ||
scale = [[UIScreen mainScreen] scale]; | ||
#else | ||
scale = [[NSScreen mainScreen] backingScaleFactor]; | ||
#endif | ||
dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | ||
NSInteger count = 0; | ||
for (NSInteger idx = 0; idx < 500; idx++) { | ||
Oriented *oriented = [[Oriented alloc] init]; | ||
CGFloat r = (rand() % 255) / 255.0f; | ||
CGFloat g = (rand() % 255) / 255.0f; | ||
CGFloat b = (rand() % 255) / 255.0f; | ||
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED | ||
oriented.dominantColor = [UIColor colorWithRed:r green:g blue:b alpha:1.0f]; | ||
#else | ||
oriented.dominantColor = [NSColor colorWithRed:r green:g blue:b alpha:1.0f]; | ||
#endif | ||
|
||
NSUInteger orientedIdx = rand() % 18; | ||
|
||
CGSize orientedSize = [orientedSizes[orientedIdx] CGSizeValue]; | ||
NSInteger orientedSizeWidth = orientedSize.width; | ||
NSInteger orientedSizeHeight = orientedSize.height; | ||
|
||
if (orientedSizeWidth > (width * scale)) { | ||
orientedSizeHeight = ((width * scale) / orientedSizeWidth) * orientedSizeHeight; | ||
orientedSizeWidth = (width * scale); | ||
} | ||
|
||
oriented.imageURL = orientedURLs[orientedIdx]; | ||
oriented.imageSize = CGSizeMake(orientedSizeWidth / scale, orientedSizeHeight / scale); | ||
|
||
dispatch_sync(dispatch_get_main_queue(), ^{ | ||
[orienteds addObject:oriented]; | ||
}); | ||
count++; | ||
} | ||
}); | ||
dispatch_group_notify(group, dispatch_get_main_queue(), ^{ | ||
if (completion) { | ||
completion(orienteds); | ||
} | ||
}); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters