Skip to content

Commit

Permalink
Merge branch 'enhance-accelerate'
Browse files Browse the repository at this point in the history
  • Loading branch information
RSully committed Aug 24, 2013
2 parents 0303914 + 2a5ae12 commit fe0664d
Show file tree
Hide file tree
Showing 9 changed files with 335 additions and 117 deletions.
6 changes: 3 additions & 3 deletions RSColorPicker.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "RSColorPicker"
s.version = "0.7.1"
s.version = "0.8.0"
s.summary = "iPhone color picker view with brightness control, opacity control, and delegation support."
s.description = <<-DESC
iPhone color picker view with brightness control, opacity control, and delegation support. Handles touch events internally. Easy to customize.
Expand All @@ -9,10 +9,10 @@ Pod::Spec.new do |s|
s.screenshots = "https://raw.github.com/RSully/RSColorPicker/v0.7.0/Example01.png", "https://raw.github.com/RSully/RSColorPicker/v0.7.0/Example02.png", "https://raw.github.com/RSully/RSColorPicker/v0.7.0/Example03.png", "https://raw.github.com/RSully/RSColorPicker/v0.7.0/Example04.png", "https://raw.github.com/RSully/RSColorPicker/v0.7.0/Example05.png", "https://raw.github.com/RSully/RSColorPicker/v0.7.0/Example06.png"
s.license = { :type => 'BSD', :file => "LICENSE.md" }
s.author = { "Ryan" => "[email protected]" }
s.source = { :git => "https://github.com/RSully/RSColorPicker.git", :tag => "v0.7.1" }
s.source = { :git => "https://github.com/RSully/RSColorPicker.git", :tag => "v0.8.0" }
s.platform = :ios, '5.0'
s.source_files = 'RSColorPicker/ColorPickerClasses/**/*.{h,m}'
s.frameworks = 'QuartzCore', 'CoreGraphics', 'UIKit'
s.frameworks = 'QuartzCore', 'CoreGraphics', 'UIKit', 'Accelerate'
s.requires_arc = true

s.public_header_files = "RSColorPicker/ColorPickerClasses/RSColorPickerView.h", "RSColorPicker/ColorPickerClasses/RSBrightnessSlider.h", "RSColorPicker/ColorPickerClasses/RSOpacitySlider.h"
Expand Down
18 changes: 18 additions & 0 deletions RSColorPicker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
2B85424116EFC8970047FFBE /* RSSelectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = 2B85423016EFC8970047FFBE /* RSSelectionView.m */; };
7FB5E81717455D820034FFB8 /* RSOpacitySlider.m in Sources */ = {isa = PBXBuildFile; fileRef = 7FB5E81617455D820034FFB8 /* RSOpacitySlider.m */; };
930D5A8016DE4D36006C38D4 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 930D5A7F16DE4D36006C38D4 /* [email protected] */; };
94A10AFB1799B6A900F0BD7E /* Accelerate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 94A10AFA1799B6A900F0BD7E /* Accelerate.framework */; };
94A10AFF179DB67C00F0BD7E /* RSGenerateOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 94A10AFE179DB67C00F0BD7E /* RSGenerateOperation.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -87,13 +89,17 @@
7FB5E81517455D820034FFB8 /* RSOpacitySlider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RSOpacitySlider.h; sourceTree = "<group>"; };
7FB5E81617455D820034FFB8 /* RSOpacitySlider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RSOpacitySlider.m; sourceTree = "<group>"; };
930D5A7F16DE4D36006C38D4 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
94A10AFA1799B6A900F0BD7E /* Accelerate.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accelerate.framework; path = System/Library/Frameworks/Accelerate.framework; sourceTree = SDKROOT; };
94A10AFD179DB67C00F0BD7E /* RSGenerateOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RSGenerateOperation.h; sourceTree = "<group>"; };
94A10AFE179DB67C00F0BD7E /* RSGenerateOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RSGenerateOperation.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
1FA35E5813F57B2700A6B347 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
94A10AFB1799B6A900F0BD7E /* Accelerate.framework in Frameworks */,
1FA35E9913F5A17E00A6B347 /* QuartzCore.framework in Frameworks */,
1FA35E6013F57B2700A6B347 /* UIKit.framework in Frameworks */,
1FA35E6213F57B2700A6B347 /* Foundation.framework in Frameworks */,
Expand Down Expand Up @@ -125,6 +131,7 @@
1FA35E5E13F57B2700A6B347 /* Frameworks */ = {
isa = PBXGroup;
children = (
94A10AFA1799B6A900F0BD7E /* Accelerate.framework */,
1FA35E9813F5A17E00A6B347 /* QuartzCore.framework */,
1FA35E5F13F57B2700A6B347 /* UIKit.framework */,
1FA35E6113F57B2700A6B347 /* Foundation.framework */,
Expand Down Expand Up @@ -171,6 +178,7 @@
2B85422C16EFC8970047FFBE /* RSColorFunctions.m */,
2B85422D16EFC8970047FFBE /* RSColorPickerView.h */,
2B85422E16EFC8970047FFBE /* RSColorPickerView.m */,
94A10AFC179DB66400F0BD7E /* Generation */,
2B85422F16EFC8970047FFBE /* RSSelectionView.h */,
2B85423016EFC8970047FFBE /* RSSelectionView.m */,
);
Expand Down Expand Up @@ -232,6 +240,15 @@
path = Manipulators;
sourceTree = "<group>";
};
94A10AFC179DB66400F0BD7E /* Generation */ = {
isa = PBXGroup;
children = (
94A10AFD179DB67C00F0BD7E /* RSGenerateOperation.h */,
94A10AFE179DB67C00F0BD7E /* RSGenerateOperation.m */,
);
name = Generation;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -316,6 +333,7 @@
2B85424116EFC8970047FFBE /* RSSelectionView.m in Sources */,
2B12A0DF1792FF46007F2A0A /* TestColorViewController.m in Sources */,
7FB5E81717455D820034FFB8 /* RSOpacitySlider.m in Sources */,
94A10AFF179DB67C00F0BD7E /* RSGenerateOperation.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
42 changes: 34 additions & 8 deletions RSColorPicker/ColorPickerClasses/RSColorFunctions.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,41 @@

#import "RSColorFunctions.h"

BMPixel RSPixelFromHSV(CGFloat H, CGFloat S, CGFloat V)
{
UIColor *color = [UIColor colorWithHue:H saturation:S brightness:V alpha:1];
CGFloat r, g, b;
[color getRed:&r green:&g blue:&b alpha:NULL];
return BMPixelMake(r, g, b, 1.0);
BMPixel RSPixelFromHSV(CGFloat H, CGFloat S, CGFloat V) {
if (S == 0) {
return BMPixelMake(V, V, V, 1.0);
}
if (H == 1) {
H = 0;
}

CGFloat var_h = H * 6.0;
// Verified `H` is never <0 so (int) is OK:
int var_i = (int)var_h;
CGFloat var_1 = V * (1.0 - S);

if (var_i == 0) {
CGFloat var_3 = V * (1.0 - S * (1.0 - (var_h - var_i)));
return BMPixelMake(V, var_3, var_1, 1.0);
} else if (var_i == 1) {
CGFloat var_2 = V * (1.0 - S * (var_h - var_i));
return BMPixelMake(var_2, V, var_1, 1.0);
} else if (var_i == 2) {
CGFloat var_3 = V * (1.0 - S * (1.0 - (var_h - var_i)));
return BMPixelMake(var_1, V, var_3, 1.0);
} else if (var_i == 3) {
CGFloat var_2 = V * (1.0 - S * (var_h - var_i));
return BMPixelMake(var_1, var_2, V, 1.0);
} else if (var_i == 4) {
CGFloat var_3 = V * (1.0 - S * (1.0 - (var_h - var_i)));
return BMPixelMake(var_3, var_1, V, 1.0);
}
CGFloat var_2 = V * (1.0 - S * (var_h - var_i));
return BMPixelMake(V, var_1, var_2, 1.0);
}

void RSHSVFromPixel(BMPixel pixel, CGFloat *h, CGFloat *s, CGFloat *v)
{

void RSHSVFromPixel(BMPixel pixel, CGFloat *h, CGFloat *s, CGFloat *v) {
UIColor *color = [UIColor colorWithRed:pixel.red green:pixel.green blue:pixel.blue alpha:1];
[color getHue:h saturation:s brightness:v alpha:NULL];
}
Expand All @@ -42,6 +67,7 @@ CGSize RSCGSizeWithScale(CGSize size, CGFloat scale) {
CGPoint RSCGPointWithScale(CGPoint point, CGFloat scale) {
return CGPointMake(point.x * scale, point.y * scale);
}

UIImage* RSUIImageWithScale(UIImage *img, CGFloat scale) {
return [UIImage imageWithCGImage:img.CGImage scale:scale orientation:UIImageOrientationUp];
}
9 changes: 8 additions & 1 deletion RSColorPicker/ColorPickerClasses/RSColorPickerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import <Accelerate/Accelerate.h>
#import "ANImageBitmapRep.h"

@class RSColorPickerView, BGRSLoupeLayer;

Expand All @@ -24,6 +26,11 @@
@property (nonatomic, weak) id <RSColorPickerViewDelegate> delegate;
@property (nonatomic, readonly) CGPoint selection;

-(UIColor*)colorAtPoint:(CGPoint)point; //Returns UIColor at a point in the RSColorPickerView
-(UIColor*)colorAtPoint:(CGPoint)point; // Returns UIColor at a point in the RSColorPickerView

+(void)prepareForDiameter:(CGFloat)diameter;
+(void)prepareForDiameter:(CGFloat)diameter padding:(CGFloat)padding;
+(void)prepareForDiameter:(CGFloat)diameter scale:(CGFloat)scale;
+(void)prepareForDiameter:(CGFloat)diameter scale:(CGFloat)scale padding:(CGFloat)padding;
+(void)prepareForDiameter:(CGFloat)diameter scale:(CGFloat)scale padding:(CGFloat)padding inBackground:(BOOL)bg;
@end
Loading

0 comments on commit fe0664d

Please sign in to comment.