under-os-image 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cce6de254082abcd877e365880fc4674ffd934fc
4
+ data.tar.gz: 303c554d01a5f8f7ea0f1f9793a8d7140f8289db
5
+ SHA512:
6
+ metadata.gz: 6b1fe00fd58c1ff12c939d49b20b937a4a45bc5e47f66c3ab2b72a3cc85394245733dff0fe014ab14e0c4e965f8daaec56aa45cbf52b2d0e54d0b6e2c62db4b6
7
+ data.tar.gz: 426215482e94af0c5e02fc9d8d2e6ca815481c82def040fa001f9b7d8370f1f55abba79e284b3ac15e77a9100ef0683074983f8e004d02438b0751be0cc81fee
@@ -0,0 +1 @@
1
+ UnderOs.extend __FILE__
@@ -0,0 +1,29 @@
1
+ module UnderOs
2
+ class Image
3
+ VERSION = '1.0.0'
4
+
5
+ def self.picker(options={})
6
+ @picker ||= Picker.new(options)
7
+ end
8
+
9
+ def self.take(&block)
10
+ picker.take(&block)
11
+ end
12
+
13
+ def self.pick(&block)
14
+ picker.pick(&block)
15
+ end
16
+
17
+ attr_accessor :_
18
+
19
+ def initialize(raw_image)
20
+ @_ = raw_image
21
+ end
22
+
23
+ def filter(params)
24
+ @filter ||= Filter.new.tap{ |f| f.image = self }
25
+ @filter.params = params
26
+ @filter.apply
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,199 @@
1
+ class UnderOs::Image
2
+ class Filter
3
+
4
+ attr_reader :image
5
+
6
+ def initialize(params={})
7
+ self.params = params
8
+ end
9
+
10
+ def apply_to(image)
11
+ self.image = image
12
+ apply
13
+ end
14
+
15
+ def image=(image)
16
+ @image = CIImage.alloc.initWithImage(
17
+ image.is_a?(UnderOs::Image) ? image._ : image)
18
+ end
19
+
20
+ def apply
21
+ UnderOs::Image.new(render)
22
+ end
23
+
24
+ def params
25
+ @params ||= {}
26
+ end
27
+
28
+ def params=(params)
29
+ @params = {} # original param values
30
+ @filters = {}
31
+
32
+ params.each do |key, value|
33
+ @params[key.to_sym] = value
34
+ self.__send__ "#{key}=", value
35
+ end
36
+ end
37
+
38
+ def saturation=(value) # 1.0 +/- 0.25
39
+ add_filter :CIColorControls, inputSaturation: value
40
+ end
41
+
42
+ def brightness=(value) # 0.0 +/- 0.25
43
+ add_filter :CIColorControls, inputBrightness: value
44
+ end
45
+
46
+ def contrast=(value) # 1.0 +/- 0.25
47
+ add_filter :CIColorControls, inputContrast: value
48
+ end
49
+
50
+ def exposure=(value) # 0.0 +/- 0.25
51
+ add_filter :CIExposureAdjust, inputEV: value
52
+ end
53
+
54
+ def vibrance=(value) # 0.0 +/- 0.25
55
+ add_filter :CIVibrance, inputAmount: value
56
+ end
57
+
58
+ def shadows=(value) # 0 +/- 1.0
59
+ add_filter :CIToneCurve, inputPoint1: CIVector.vectorWithX(0.2, Y: 0.2 + (0.25 * value))
60
+ end
61
+
62
+ def midtone=(value) # 0 +/- 1.0
63
+ add_filter :CIToneCurve, inputPoint2: CIVector.vectorWithX(0.5, Y: 0.5 + (0.25 * value))
64
+ end
65
+
66
+ def highlights=(value) # 0 +/- 1.0
67
+ add_filter :CIToneCurve, inputPoint3: CIVector.vectorWithX(0.75, Y: 0.75 + (0.25 * value))
68
+ end
69
+
70
+ def sharpen=(value) # 0.5 +/- 0.5
71
+ add_filter :CIUnsharpMask, inputRadius: 1.5, inputIntensity: value
72
+ end
73
+
74
+ def temperature=(value) # 6500 +/- 1500
75
+ add_filter :CITemperatureAndTint, inputTargetNeutral: CIVector.vectorWithX(value, Y:0)
76
+ end
77
+
78
+ def tint=(value) # 0.0 +/- 50
79
+ add_filter :CITemperatureAndTint, inputNeutral: CIVector.vectorWithX(6500, Y:-(value))
80
+ end
81
+
82
+ def sepia=(value)
83
+ add_filter :CISepiaTone, inputIntensity: value
84
+ end
85
+
86
+ def vignette_radius=(value) # 1.0 +/- 0.5
87
+ add_filter :CIVignette, inputRadius: value
88
+ end
89
+
90
+ def vignette_intensity=(value) # 1.0 +/- 1.0
91
+ add_filter :CIVignette, inputIntensity: value
92
+ end
93
+
94
+ def pixellate_scale=(value)
95
+ add_filter :CIPixellate, inputScale: value
96
+ end
97
+
98
+ def pixellate_center=(value)
99
+ add_filter :CIPixellate, inputCenter: value
100
+ end
101
+
102
+ def mono_color=(value) # CIColor.colorWithRed(value, green:value, blue:value, alpha:1.0)
103
+ add_filter :CIColorMonochrome, inputColor: value
104
+ end
105
+
106
+ def mono_intensity=(value)
107
+ add_filter :CIColorMonochrome, inputIntensity: value
108
+ end
109
+
110
+ def posterize=(value)
111
+ add_filter :CIColorPosterize, inputLevels: value
112
+ end
113
+
114
+ def scale=(value)
115
+ add_filter :CILanczosScaleTransform, inputScale: value
116
+ end
117
+
118
+ def aspect_ratio=(value)
119
+ add_filter :CILanczosScaleTransform, inputAspectRatio: value
120
+ end
121
+
122
+ def crop=(value)
123
+ add_filter :CICrop, inputRectangle: value
124
+ end
125
+
126
+ def straighten=(value)
127
+ add_filter :CIStraightenFilter, inputAngle: value
128
+ end
129
+
130
+
131
+ def method_missing(name, *args, &block)
132
+ if respond_to?("#{name}=")
133
+ @params[name.to_sym]
134
+ else
135
+ super
136
+ end
137
+ end
138
+
139
+ def render(image=@image)
140
+ image = CIImage.alloc.initWithImage(image.is_a?(UnderOs::Image) ? image._ : image) if image != @image
141
+ image = apply_filters_to(image)
142
+ cg_image = UnderOs::Image::Filter.context.createCGImage(image, fromRect:image.extent)
143
+ new_image = UIImage.imageWithCGImage(cg_image)
144
+ CGImageRelease(cg_image)
145
+
146
+ new_image
147
+ end
148
+
149
+ # shared EAGL context
150
+ def self.context
151
+ @context ||= begin
152
+ gl_context = EAGLContext.alloc.initWithAPI(KEAGLRenderingAPIOpenGLES2)
153
+ options = {KCIContextWorkingColorSpace => nil}
154
+ CIContext.contextWithEAGLContext(gl_context, options:options)
155
+ end
156
+ end
157
+
158
+ protected
159
+
160
+ def apply_filters_to(image)
161
+ @filters.each do |name, filter|
162
+ if filter.is_a?(Proc)
163
+ image = instance_exec image, &filter
164
+ else
165
+ filter = self.class.filter_for(name, filter)
166
+ filter.setValue(image, forKey: 'inputImage')
167
+ image = filter.outputImage
168
+ filter.setValue(nil, forKey: 'inputImage')
169
+ end
170
+ end
171
+
172
+ image
173
+ end
174
+
175
+ private
176
+
177
+ def add_filter(name, values={})
178
+ @filters[name] ||= {}
179
+
180
+ values.each do |key, value|
181
+ @filters[name][key] = value
182
+ end
183
+ end
184
+
185
+ def self.filter_for(name, params)
186
+ @filters_cache ||= {}
187
+ @filters_cache[name] ||= CIFilter.filterWithName(name.to_s)
188
+
189
+ filter = @filters_cache[name]
190
+ filter.setDefaults
191
+
192
+ params.each do |key, value|
193
+ filter.setValue(value, forKey: key.to_s)
194
+ end
195
+
196
+ filter
197
+ end
198
+ end
199
+ end
@@ -0,0 +1,36 @@
1
+ #
2
+ # A little module to wrap up the built-in
3
+ # iOS images picking/taking
4
+ #
5
+ class UnderOs::Image::Picker
6
+ def initialize(options={})
7
+ @animated = options.delete(:animated) || true
8
+ @_ = UIImagePickerController.alloc.init
9
+ @_.delegate = self
10
+ end
11
+
12
+ def take(&block)
13
+ if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceTypeCamera)
14
+ @_.setSourceType(UIImagePickerControllerSourceTypeCamera)
15
+ start(&block)
16
+ else
17
+ pick(&block)
18
+ end
19
+ end
20
+
21
+ def pick(&block)
22
+ @_.setSourceType(UIImagePickerControllerSourceTypePhotoLibrary)
23
+ start(&block)
24
+ end
25
+
26
+ def start(&block)
27
+ @block = block
28
+ @page = UnderOs::App.history.current_page._
29
+ @page.presentViewController @_, animated: @animated, completion: nil
30
+ end
31
+
32
+ def imagePickerController(picker, didFinishPickingImage:image, editingInfo:info)
33
+ @page.dismissModalViewControllerAnimated(@animated)
34
+ @block.call(UnderOs::Image.new(image))
35
+ end
36
+ end
@@ -0,0 +1,17 @@
1
+ #
2
+ # creates a new image that fits the given size
3
+ #
4
+ class UnderOs::Image
5
+ def resize(size)
6
+ size = UOS::Point.new(size)
7
+ ratio = size.x * 2 / @_.size.width
8
+ new_size = CGSizeMake(size.x * 2, @_.size.height * ratio)
9
+
10
+ UIGraphicsBeginImageContext(new_size)
11
+ @_.drawInRect(CGRectMake(0,0,new_size.width,new_size.height))
12
+ new_image = UIGraphicsGetImageFromCurrentImageContext()
13
+ UIGraphicsEndImageContext()
14
+
15
+ self.class.new(new_image)
16
+ end
17
+ end
@@ -0,0 +1,8 @@
1
+ class UnderOs::UI::Image
2
+ alias :src_before_image= :src=
3
+
4
+ def src=(value)
5
+ value = value._ if value.is_a?(UnderOs::Image)
6
+ self.src_before_image = value
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: under-os-image
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Nikolay Nemshilov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: under-os-ui
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: The images handling API for UnderOS
42
+ email:
43
+ - nemshilov@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/under-os-image.rb
49
+ - lib/under_os/image.rb
50
+ - lib/under_os/image/filter.rb
51
+ - lib/under_os/image/picker.rb
52
+ - lib/under_os/image/resize.rb
53
+ - lib/under_os/ui/image.rb
54
+ homepage:
55
+ licenses:
56
+ - MIT
57
+ metadata: {}
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 2.2.2
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: The images handling API for UnderOS
78
+ test_files: []