forked from alejandrojapkin/CocoaLUT
/
LUT.h
212 lines (161 loc) · 6.8 KB
/
LUT.h
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
//
// LUT.h
// DropLUT
//
// Created by Wil Gieseler on 12/15/13.
// Copyright (c) 2013 Wil Gieseler. All rights reserved.
//
#import <Foundation/Foundation.h>
@class LUTFormatter;
@class LUTColor;
typedef NS_ENUM(NSInteger, LUT1DSwizzleChannelsMethod) {
LUT1DSwizzleChannelsMethodAverageRGB,
LUT1DSwizzleChannelsMethodEdgesRGB,
LUT1DSwizzleChannelsMethodRedCopiedToRGB,
LUT1DSwizzleChannelsMethodGreenCopiedToRGB,
LUT1DSwizzleChannelsMethodBlueCopiedToRGB
};
typedef NS_ENUM(NSInteger, LUTImageRenderPath) {
LUTImageRenderPathCoreImage,
LUTImageRenderPathCoreImageSoftware,
LUTImageRenderPathDirect
};
/**
* A three-dimensional color lookup table.
*/
@interface LUT : NSObject <NSCopying>
/**
* A lattice that represents the code values of the look up table.
*/
@property (strong) NSString *title;
@property (strong) NSString *descriptionText;
@property (assign) NSUInteger size;
@property (assign) double inputLowerBound;
@property (assign) double inputUpperBound;
/**
* Arbitrary metadata.
*/
@property (strong) NSMutableDictionary *metadata;
/**
* LUT File specific settings such as the integer output depth (for integer luts) and the variant type of the file (ex: .3dl has a Nuke and Lustre type). This shouldn't be modified after setting.
*/
@property (strong) NSDictionary *passthroughFileOptions;
/**
* Returns a new `LUT` by reading the contents of a file represented by a file URL. It will automatically detect the type of LUT file format.
*
* @param url A file URL.
*
* @return A new `LUT` with the contents of url.
*/
+ (instancetype)LUTFromURL:(NSURL *)url;
- (NSData *)dataFromLUTWithFormatterID:(NSString *)formatterID
options:(NSDictionary *)options;
- (instancetype)initWithSize:(NSUInteger)size
inputLowerBound:(double)inputLowerBound
inputUpperBound:(double)inputUpperBound;
+ (instancetype)LUTOfSize:(NSUInteger)size
inputLowerBound:(double)inputLowerBound
inputUpperBound:(double)inputUpperBound;
/**
* Returns a new `LUT` that maps input colors to output colors with no transformation.
*
* @param size The length of one edge of the cube for the new LUT.
*
* @return A new `LUT` with a lattice size of size.
*/
+ (instancetype)LUTIdentityOfSize:(NSUInteger)size
inputLowerBound:(double)inputLowerBound
inputUpperBound:(double)inputUpperBound;
- (void)copyMetaPropertiesFromLUT:(LUT *)lut;
- (void) LUTLoopWithBlock:( void ( ^ )(size_t r, size_t g, size_t b) )block;
/**
* Returns a new `LUT` with a specified edge size. The LUT generated by trilinearly interpolating the receiver's lattice.
*
* @param newSize The length of one edge of the cube for the new LUT.
*
* @return A new LUT with a lattice of size newSize.
*/
- (instancetype)LUTByResizingToSize:(NSUInteger)newSize;
/**
* Returns a new `LUT` that is the original LUT of original size combined with otherLUT.
*
* @param otherLUT The LUT to apply to the current lut.
*
* @return A new LUT with the same lattice size as self.lattice.size.
*/
- (LUT *)LUTByCombiningWithLUT:(LUT *)otherLUT;
- (instancetype)LUTByClampingLowerBound:(double)lowerBound
upperBound:(double)upperBound;
- (instancetype)LUTByClampingLowerBoundOnly:(double)lowerBound;
- (instancetype)LUTByClampingUpperBoundOnly:(double)upperBound;
- (instancetype)LUTByRemappingValuesWithInputLow:(double)inputLow
inputHigh:(double)inputHigh
outputLow:(double)outputLow
outputHigh:(double)outputHigh
bounded:(BOOL)bounded;
- (instancetype)LUTByRemappingFromInputLowColor:(LUTColor *)inputLowColor
inputHigh:(LUTColor *)inputHighColor
outputLow:(LUTColor *)outputLowColor
outputHigh:(LUTColor *)outputHighColor
bounded:(BOOL)bounded;
- (instancetype)LUTByChangingStrength:(double)strength;
- (instancetype)LUTByChangingInputLowerBound:(double)inputLowerBound inputUpperBound:(double)inputUpperBound;
- (instancetype)LUTByInvertingColor;
- (bool)equalsIdentityLUT;
- (bool)equalsLUT:(LUT *)comparisonLUT;
- (LUTColor *)identityColorAtR:(double)redPoint g:(double)greenPoint b:(double)bluePoint;
- (LUTColor *)colorAtColor:(LUTColor *)color;
- (LUTColor *)colorAtR:(NSUInteger)r g:(NSUInteger)g b:(NSUInteger)b;
- (LUTColor *)colorAtInterpolatedR:(double)redPoint g:(double)greenPoint b:(double)bluePoint;
- (LUTColor *)maximumOutputColor;
- (LUTColor *)minimumOutputColor;
- (double)maximumOutputValue;
- (double)minimumOutputValue;
- (void)setColor:(LUTColor *)color r:(NSUInteger)r g:(NSUInteger)g b:(NSUInteger)b;
/**
* Returns a Core Image filter that will apply the receiver's transformation in a particular color space.
*
* @param colorSpace The desired color space to use on the filter. Pass `nil` to get a `CIFilter` of type `CIColorCube`.
*
* @return A CIFilter of type `CIColorCubeWithColorSpace`.
*/
- (CIFilter *)coreImageFilterWithColorSpace:(CGColorSpaceRef)colorSpace;
/**
* Returns a Core Image filter that will apply the receiver's transformation in the color space of the main screen.
*
* Due to limitations of Core Image, if the receiver has a lattice size larger than 64, the returned CIFilter will represent a scaled version of the LUT as scaled by LUTByResizingToSize:
*
* @return A CIFilter of type `CIColorCubeWithColorSpace` or `CIColorCube`.
*/
- (CIFilter *)coreImageFilterWithCurrentColorSpace;
/**
* Returns a `CIImage` with the receiver's color transformation applied.
*
* @param image The input `CIImage` you wish transform.
*
* @return A `CIImage` with a `CIFilter` applied that represents the receiver's color transformation.
*/
- (CIImage *)processCIImage:(CIImage *)image;
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
/**
* Returns a `UIImage` with the receiver's color transformation applied.
*
* @param image The input `UIImage` you wish transform.
* @param colorSpace The desired color space to use on the filter. Pass `nil` to apply the transformation without color management.
*
* @return A UIImage with the receiver's color transformation applied.
*/
- (UIImage *)processUIImage:(UIImage *)image withColorSpace:(CGColorSpaceRef)colorSpace;
#elif TARGET_OS_MAC
/**
* Returns an `NSImage` with the receiver's color transformation applied.
*
* @param image The input `NSImage` you wish transform.
* @param renderPath The rendering path to use.
*
* @return A `NSImage` with the receiver's color transformation applied.
*/
- (NSImage *)processNSImage:(NSImage *)image
renderPath:(LUTImageRenderPath)renderPath;
#endif
@end