sass-softlight 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sass-softlight.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Albert Tholen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Sass::Softlight
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'sass-softlight'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install sass-softlight
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,85 @@
1
+ require "sass"
2
+
3
+ module Sass::Script::Functions
4
+ def normalize( x )
5
+ x / 255
6
+ end
7
+
8
+ def denormalize( x )
9
+ x * 255
10
+ end
11
+
12
+ def scale( arg )
13
+ _rgba_unscaled = {}
14
+ arg.each do | key, val |
15
+ if key == :alpha then next end
16
+ _rgba_unscaled[ key ] = normalize( val.to_f )
17
+ end
18
+ _rgba_unscaled[ :alpha ] = arg[ :alpha ]
19
+ _rgba_unscaled
20
+ end
21
+
22
+ def unscale( arg )
23
+ _rgba_unscaled = {}
24
+ arg.each do | key, val |
25
+ if key == :alpha then next end
26
+ _rgba_unscaled[ key ] = denormalize( val ).to_i
27
+ end
28
+ _rgba_unscaled[ :alpha ] = arg[ :alpha ]
29
+ _rgba_unscaled
30
+ end
31
+
32
+ def premultiply( arg )
33
+ _rgba = {}
34
+ arg.each do | key, val |
35
+ if key == :alpha then next end
36
+ _rgba[ key ] = val * arg[ :alpha ]
37
+ end
38
+ _rgba[:alpha] = arg[:alpha]
39
+ _rgba
40
+ end
41
+
42
+ def union( x, y )
43
+ x + y - ( x * y )
44
+ end
45
+
46
+ def blend( s_a, s_ca, d_a, d_ca )
47
+ m = d_ca / d_a
48
+ if 2 * s_ca <= s_a
49
+ d_ca_prime = d_ca * (s_a + (2 * s_ca - s_a) * (1 - m)) + s_ca * (1 - d_a) + d_ca * (1 - s_a)
50
+ elsif 2 * s_ca > s_a and 4 * d_ca <= d_a
51
+ d_ca_prime = d_ca * s_a + d_a * (2 * s_ca - s_a) * (4 * m * (4 * m + 1) * (m - 1) + 7 * m) + s_ca * (1 - d_a) + d_ca * (1 - s_a)
52
+ elsif 2 * s_ca > s_a and 4 * d_ca > d_a
53
+ d_ca_prime = d_a * (2 * s_ca - s_a) * (m**0.5 - m) + s_ca - s_ca * d_a + d_ca
54
+ end
55
+ d_ca_prime
56
+ end
57
+
58
+ def self.softlight( source, canvas )
59
+ Sass::Script::assert_type source, :Color
60
+ Sass::Script::assert_type canvas, :Color
61
+
62
+ src = { r: source.red, g: source.green, b: source.blue, alpha: source.alpha }
63
+ dest = { r: canvas.red, g: canvas.green, b: canvas.blue, alpha: canvas.alpha }
64
+
65
+ alpha_s = src[:alpha]
66
+ alpha_d = dest[:alpha]
67
+
68
+ composite = {}
69
+ alpha_r = union( alpha_d, alpha_s )
70
+ if alpha_r == 0 then alpha_r = 1e-10 end
71
+
72
+ normal_source = premultiply( scale( src ) )
73
+ normal_canvas = premultiply( scale( dest ) )
74
+
75
+ normal_source.each do | key, val |
76
+ if key == :alpha then next end
77
+ composite[ key ] = blend(alpha_s, normal_source[key], alpha_d, normal_canvas[key])
78
+ end
79
+ composite[ :alpha ] = alpha_r
80
+ c = unscale( composite )
81
+ Sass::Script::Color.new( { red: c[:r], green: c[:g], blue: c[:b], alpha: c[:alpha]} )
82
+ end
83
+
84
+ declare :softlight, :args => [:source, :canvas]
85
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.authors = ["Albert Tholen"]
5
+ gem.email = ["albert@luatechnologies.com"]
6
+ gem.description = %q{SassScript extension to bring the math behind Photoshop's powerful soft-light gradient blending mode to Sass, which eliminates the need for making soft-light gradient backgrounds manually.}
7
+ gem.summary = %q{Photoshop soft light blending mode in SassScript}
8
+ gem.homepage = ""
9
+
10
+ # gem.files = ['lib/sass-softlight.rb']
11
+ gem.files = `git ls-files`.split($\)
12
+ # gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ # gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "sass-softlight"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = "0.0.1"
17
+
18
+ # gem.add_development_dependency "rspec", "~> 2.6"
19
+ gem.add_dependency "sass"
20
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sass-softlight
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Albert Tholen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-31 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sass
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: SassScript extension to bring the math behind Photoshop's powerful soft-light
31
+ gradient blending mode to Sass, which eliminates the need for making soft-light
32
+ gradient backgrounds manually.
33
+ email:
34
+ - albert@luatechnologies.com
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - .gitignore
40
+ - Gemfile
41
+ - LICENSE
42
+ - README.md
43
+ - Rakefile
44
+ - lib/sass-softlight.rb
45
+ - sass-softlight.gemspec
46
+ homepage: ''
47
+ licenses: []
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 1.8.19
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Photoshop soft light blending mode in SassScript
70
+ test_files: []