greyn 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a878040ef739483ad77684205d66ba9ae66c4d3e
4
+ data.tar.gz: 9ee84f716946ad977455913f5bd967eeabfee0e3
5
+ SHA512:
6
+ metadata.gz: e46443d29acb3c15881ce82fb7f8e5bd204bbbfc23618a117ba9022f91b283763e40d621990012fca16f903099caad148938dd3564e8ee3a20744c0fb7539c19
7
+ data.tar.gz: f7d0a818c9795a7233d37760d4632011c74a59a6de8d1831a3f73834faa15ea466aaa65b01a7cc03f313da590cdc8c2d577b143c24c86d3b253967def5014b35
data/.gitignore ADDED
@@ -0,0 +1,37 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
35
+ .DS_Store
36
+
37
+ test.png
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in greyn.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,64 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ greyn (0.2.0)
5
+ chunky_png (~> 1.3, >= 1.3.1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ celluloid (0.16.0)
11
+ timers (~> 4.0.0)
12
+ chunky_png (1.3.1)
13
+ coderay (1.1.0)
14
+ diff-lcs (1.2.5)
15
+ ffi (1.9.3)
16
+ formatador (0.2.5)
17
+ guard (2.6.1)
18
+ formatador (>= 0.2.4)
19
+ listen (~> 2.7)
20
+ lumberjack (~> 1.0)
21
+ pry (>= 0.9.12)
22
+ thor (>= 0.18.1)
23
+ guard-rspec (4.3.1)
24
+ guard (~> 2.1)
25
+ rspec (>= 2.14, < 4.0)
26
+ hitimes (1.2.2)
27
+ listen (2.7.9)
28
+ celluloid (>= 0.15.2)
29
+ rb-fsevent (>= 0.9.3)
30
+ rb-inotify (>= 0.9)
31
+ lumberjack (1.0.9)
32
+ method_source (0.8.2)
33
+ pry (0.10.1)
34
+ coderay (~> 1.1.0)
35
+ method_source (~> 0.8.1)
36
+ slop (~> 3.4)
37
+ rb-fsevent (0.9.4)
38
+ rb-inotify (0.9.5)
39
+ ffi (>= 0.5.0)
40
+ rspec (3.0.0)
41
+ rspec-core (~> 3.0.0)
42
+ rspec-expectations (~> 3.0.0)
43
+ rspec-mocks (~> 3.0.0)
44
+ rspec-core (3.0.0)
45
+ rspec-support (~> 3.0.0)
46
+ rspec-expectations (3.0.0)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.0.0)
49
+ rspec-mocks (3.0.1)
50
+ rspec-support (~> 3.0.0)
51
+ rspec-support (3.0.0)
52
+ slop (3.6.0)
53
+ thor (0.19.1)
54
+ timers (4.0.0)
55
+ hitimes
56
+
57
+ PLATFORMS
58
+ ruby
59
+
60
+ DEPENDENCIES
61
+ bundler (~> 1.5)
62
+ greyn!
63
+ guard-rspec (~> 4.3, >= 4.3.1)
64
+ rspec (~> 3.0)
data/Guardfile ADDED
@@ -0,0 +1,33 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ # Note: The cmd option is now required due to the increasing number of ways
5
+ # rspec may be run, below are examples of the most common uses.
6
+ # * bundler: 'bundle exec rspec'
7
+ # * bundler binstubs: 'bin/rspec'
8
+ # * spring: 'bin/rsspec' (This will use spring if running and you have
9
+ # installed the spring binstubs per the docs)
10
+ # * zeus: 'zeus rspec' (requires the server to be started separetly)
11
+ # * 'just' rspec: 'rspec'
12
+ guard :rspec, cmd: 'bundle exec rspec' do
13
+ watch(%r{^spec/.+_spec\.rb$})
14
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
15
+ watch('spec/spec_helper.rb') { "spec" }
16
+
17
+ # Rails example
18
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
19
+ watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
20
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
21
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
22
+ watch('config/routes.rb') { "spec/routing" }
23
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
24
+ watch('spec/rails_helper.rb') { "spec" }
25
+
26
+ # Capybara features specs
27
+ watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
28
+
29
+ # Turnip features and steps
30
+ watch(%r{^spec/acceptance/(.+)\.feature$})
31
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
32
+ end
33
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Andrew Curry
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.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Greyn
2
+
3
+ Easily convert a PNG to greyscale. Just PNGs. Zero configuration.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'greyn'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install greyn
18
+
19
+ ## Usage
20
+
21
+ greyn path/to/image.png
22
+
23
+ This will generate 3 new PNGs in the current directory: `image_luma.png`, `image_avg.png`, and `image_light.png`. Each image is generated using a different algorithm.
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( http://github.com/acurry/greyn/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/greyn ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'greyn'
4
+ Greyn::convert(ARGV[0])
data/greyn.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'greyn/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "greyn"
8
+ spec.version = Greyn::VERSION
9
+ spec.authors = ["Andrew Curry"]
10
+ spec.email = ["andrew.d.curry@gmail.com"]
11
+ spec.summary = %q{Easily convert a PNG to greyscale.}
12
+ spec.description = %q{Use greyn to convert any PNG to 3 greyscale versions at once - Luma, RGB Average, and Light.}
13
+ spec.homepage = "https://github.com/acurry/greyn"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rspec", "~> 3.0"
23
+ spec.add_development_dependency "guard-rspec", "~> 4.3", ">= 4.3.1"
24
+
25
+ spec.add_runtime_dependency "chunky_png", "~> 1.3", '>= 1.3.1'
26
+ end
@@ -0,0 +1,3 @@
1
+ module Greyn
2
+ VERSION = "0.3.0"
3
+ end
data/lib/greyn.rb ADDED
@@ -0,0 +1,21 @@
1
+ require "greyn/version"
2
+ require "greyscale"
3
+ require "chunky_png"
4
+
5
+ module Greyn
6
+
7
+ def self.base_filename file
8
+ File.basename(file).split('.')[0]
9
+ end
10
+
11
+ def self.convert file
12
+ basename = self.base_filename file
13
+
14
+ [:avg, :light, :luma].each do |f|
15
+ img = ChunkyPNG::Image::from_file(File.expand_path(file))
16
+ Greyscale::greyscale(img, f)
17
+ img.save("./#{basename}_#{f}.png")
18
+ end
19
+ end
20
+
21
+ end
data/lib/greyscale.rb ADDED
@@ -0,0 +1,29 @@
1
+ require 'chunky_png'
2
+
3
+ module Greyscale
4
+
5
+ def self.luma(r, g, b)
6
+ 0.21*r + 0.72*g + 0.07*b
7
+ end
8
+
9
+ def self.avg(r, g, b)
10
+ (r + g + b) / 3
11
+ end
12
+
13
+ def self.light(r, g, b)
14
+ ([r,g,b].max + [r,g,b].min) / 2
15
+ end
16
+
17
+ def self.greyscale(img, f)
18
+ width = img.width - 1
19
+ height = img.height - 1
20
+
21
+ for x in 0..width do
22
+ for y in 0..height do
23
+ col = self.send(f, ChunkyPNG::Color.r(img[x,y]), ChunkyPNG::Color.g(img[x,y]), ChunkyPNG::Color.b(img[x,y])).to_i
24
+ img[x,y] = ChunkyPNG::Color.rgb(col, col, col)
25
+ end
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,30 @@
1
+ require 'greyscale'
2
+
3
+ test_greyscale_pixels = {
4
+ :luma => [255, 892679679, 3082270719, 286331391],
5
+ :avg => [255, 1431655935, 1431655935, 1431655935],
6
+ :light => [255, 2139062271, 2139062271, 2139062271]
7
+ }
8
+
9
+ describe Greyscale do
10
+ it "computes the luma value" do
11
+ expect(subject::luma(1, 1, 1)).to eq 1.0
12
+ end
13
+
14
+ it "computes the avg value" do
15
+ expect(subject::avg(1,1,1)).to eq 1.0
16
+ end
17
+
18
+ it "computes the light value" do
19
+ expect(subject::light(3,2,1)).to eq 2.0
20
+ end
21
+
22
+ [:luma, :avg, :light].each do |f|
23
+ it "computes the greyscale of an image using #{f.to_s}" do
24
+ orig = ChunkyPNG::Image.from_file(File.expand_path('./spec/greyscale_spec_test.png'))
25
+ Greyscale::greyscale(orig, f)
26
+
27
+ expect(orig.pixels).to match_array(test_greyscale_pixels[f])
28
+ end
29
+ end
30
+ end
Binary file
@@ -0,0 +1,78 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, make a
10
+ # separate helper file that requires this one and then use it only in the specs
11
+ # that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ RSpec.configure do |config|
18
+ # The settings below are suggested to provide a good initial experience
19
+ # with RSpec, but feel free to customize to your heart's content.
20
+ =begin
21
+ # These two settings work together to allow you to limit a spec run
22
+ # to individual examples or groups you care about by tagging them with
23
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
24
+ # get run.
25
+ config.filter_run :focus
26
+ config.run_all_when_everything_filtered = true
27
+
28
+ # Many RSpec users commonly either run the entire suite or an individual
29
+ # file, and it's useful to allow more verbose output when running an
30
+ # individual spec file.
31
+ if config.files_to_run.one?
32
+ # Use the documentation formatter for detailed output,
33
+ # unless a formatter has already been configured
34
+ # (e.g. via a command-line flag).
35
+ config.default_formatter = 'doc'
36
+ end
37
+
38
+ # Print the 10 slowest examples and example groups at the
39
+ # end of the spec run, to help surface which specs are running
40
+ # particularly slow.
41
+ config.profile_examples = 10
42
+
43
+ # Run specs in random order to surface order dependencies. If you find an
44
+ # order dependency and want to debug it, you can fix the order by providing
45
+ # the seed, which is printed after each run.
46
+ # --seed 1234
47
+ config.order = :random
48
+
49
+ # Seed global randomization in this process using the `--seed` CLI option.
50
+ # Setting this allows you to use `--seed` to deterministically reproduce
51
+ # test failures related to randomization by passing the same `--seed` value
52
+ # as the one that triggered the failure.
53
+ Kernel.srand config.seed
54
+
55
+ # rspec-expectations config goes here. You can use an alternate
56
+ # assertion/expectation library such as wrong or the stdlib/minitest
57
+ # assertions if you prefer.
58
+ config.expect_with :rspec do |expectations|
59
+ # Enable only the newer, non-monkey-patching expect syntax.
60
+ # For more details, see:
61
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
62
+ expectations.syntax = :expect
63
+ end
64
+
65
+ # rspec-mocks config goes here. You can use an alternate test double
66
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
67
+ config.mock_with :rspec do |mocks|
68
+ # Enable only the newer, non-monkey-patching expect syntax.
69
+ # For more details, see:
70
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
71
+ mocks.syntax = :expect
72
+
73
+ # Prevents you from mocking or stubbing a method that does not exist on
74
+ # a real object. This is generally recommended.
75
+ mocks.verify_partial_doubles = true
76
+ end
77
+ =end
78
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: greyn
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Curry
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard-rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.3'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 4.3.1
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '4.3'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 4.3.1
61
+ - !ruby/object:Gem::Dependency
62
+ name: chunky_png
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.3'
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: 1.3.1
71
+ type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '1.3'
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 1.3.1
81
+ description: Use greyn to convert any PNG to 3 greyscale versions at once - Luma,
82
+ RGB Average, and Light.
83
+ email:
84
+ - andrew.d.curry@gmail.com
85
+ executables:
86
+ - greyn
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - Guardfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/greyn
99
+ - greyn.gemspec
100
+ - lib/greyn.rb
101
+ - lib/greyn/version.rb
102
+ - lib/greyscale.rb
103
+ - spec/greyscale_spec.rb
104
+ - spec/greyscale_spec_test.png
105
+ - spec/spec_helper.rb
106
+ homepage: https://github.com/acurry/greyn
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.2.0
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Easily convert a PNG to greyscale.
130
+ test_files:
131
+ - spec/greyscale_spec.rb
132
+ - spec/greyscale_spec_test.png
133
+ - spec/spec_helper.rb