jpeg 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2b512a8178edabb2a12690e9a276ad5606e0a80b
4
- data.tar.gz: aaba7c6ba93a72a70523022f8ec9755520773172
3
+ metadata.gz: 93785b2c60448a6fa4e9bf5b69de642d1ba0099e
4
+ data.tar.gz: 31ae30b5e411487c1c3d4436a6496a9dc2cdbd8a
5
5
  SHA512:
6
- metadata.gz: d161cfb5425cd64037ae7f264e374a97a1a232dfc9215cb36f65b26c29601e5e5e713c88813b9594c72db7dda9f934e33e81f0807c7da854d8fe604046e5cfc6
7
- data.tar.gz: 25122f30d0b14743f57007162fc4c223e507f2f257120c3d36cc55d7ba4b4b65160e90bd5f215ae790281ab5843de58b7c9937ace6b46102052f3b9d033af697
6
+ metadata.gz: cc3ba62f9d815a63e620c86a95cc7ca12b0c1e2c4f8ab78bf505e38988b8ecf700a699fe47e6f39ac27a1bede8f9eff79d12ca3e4331dd7a9965bd54623e00b8
7
+ data.tar.gz: 4cb12a28680e11496716f216d0aa355ac269cf68e012078ede2895b7bfd1beb336b3edaf3dec42c4206a02b2c9b1fb7705a35bcc4ee524bed40bdbc6f586a824
data/.rspec CHANGED
@@ -1 +1,3 @@
1
+ --require spec_helper
1
2
  --color
3
+ --format doc
@@ -0,0 +1,2 @@
1
+ Style/Documentation:
2
+ Enabled: false
@@ -1,6 +1,7 @@
1
+ language: ruby
2
+ sudo: false
3
+ cache: bundle
1
4
  before_script:
2
5
  - rake compile
3
6
  rvm:
4
- - 1.9.3
5
- - 2.0.0
6
- - 2.1.5
7
+ - 2.3.1
@@ -0,0 +1,25 @@
1
+ guard :rspec, cmd: 'bundle exec rspec' do
2
+ require 'guard/rspec/dsl'
3
+ dsl = Guard::RSpec::Dsl.new(self)
4
+
5
+ # Feel free to open issues for suggestions and improvements
6
+
7
+ # RSpec files
8
+ rspec = dsl.rspec
9
+ watch(rspec.spec_helper) { rspec.spec_dir }
10
+ watch(rspec.spec_support) { rspec.spec_dir }
11
+ watch(rspec.spec_files)
12
+
13
+ # Ruby files
14
+ ruby = dsl.ruby
15
+ dsl.watch_spec_files_for(ruby.lib_files)
16
+ end
17
+
18
+ guard :rake, task: 'compile' do
19
+ watch(%r{ext/.*$})
20
+ end
21
+
22
+ guard :rubocop, cli: '--auto-correct' do
23
+ watch(/.+\.rb$/)
24
+ watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
25
+ end
data/README.md CHANGED
@@ -32,6 +32,11 @@ jpeg.height # => 1080
32
32
  jpeg.color_info # => :rgb or :gray
33
33
  jpeg.rgb? # => true
34
34
  jpeg.gray? # => false
35
+
36
+
37
+ dot = jpeg.at(1920, 500) #=> <Jpeg::Color r=0x00 g=0xaa b=0xff>
38
+ dot.rgb #=> [0, 170, 255]
39
+ dot.to_s #=> '#00aaff'
35
40
  ```
36
41
 
37
42
  ## Contributing
data/Rakefile CHANGED
@@ -1,12 +1,12 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
7
7
 
8
8
  require 'rake/extensiontask'
9
9
 
10
- Rake::ExtensionTask.new("jpeg") do |ext|
11
- ext.lib_dir = "lib/jpeg"
10
+ Rake::ExtensionTask.new('jpeg') do |ext|
11
+ ext.lib_dir = 'lib/jpeg'
12
12
  end
@@ -1,6 +1,4 @@
1
- require "mkmf"
1
+ require 'mkmf'
2
2
 
3
3
  dir_config('jpeglib')
4
- if have_header('jpeglib.h') and have_library('jpeg')
5
- create_makefile('jpeg/jpeg')
6
- end
4
+ create_makefile('jpeg/jpeg') if have_header('jpeglib.h') && have_library('jpeg')
@@ -74,7 +74,7 @@ static void jpeg_image_s_set_read_source(struct rb_jpeg_image *p_jpeg) {
74
74
 
75
75
  } else {
76
76
 
77
- #ifdef jpeg_mem_src
77
+ #if JPEG_LIB_VERSION >= 80
78
78
  jpeg_mem_src(p_jpeg->read, (unsigned char *) p_jpeg->buffer, p_jpeg->buffer_len);
79
79
  #else
80
80
  if ((p_jpeg->fp = fmemopen(p_jpeg->buffer, p_jpeg->buffer_len, "rb")) == NULL) {
@@ -4,24 +4,29 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'jpeg/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "jpeg"
7
+ spec.name = 'jpeg'
8
8
  spec.version = Jpeg::VERSION
9
- spec.authors = ["masarakki"]
10
- spec.email = ["masaki@hisme.net"]
11
- spec.extensions = ["ext/jpeg/extconf.rb"]
12
- spec.summary = "libjpeg wrapper for ruby"
13
- spec.description = "libjpeg wrapper for ruby"
14
- spec.homepage = "http://github.com/masarakki/jpeg"
15
- spec.license = "MIT"
9
+ spec.authors = ['masarakki']
10
+ spec.email = ['masaki@hisme.net']
11
+ spec.extensions = ['ext/jpeg/extconf.rb']
12
+ spec.summary = 'libjpeg wrapper for ruby'
13
+ spec.description = 'libjpeg wrapper for ruby'
14
+ spec.homepage = 'http://github.com/masarakki/jpeg'
15
+ spec.license = 'MIT'
16
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0")
18
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
- spec.require_paths = ["lib"]
20
+ spec.require_paths = ['lib']
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.6"
23
- spec.add_development_dependency "rake"
24
- spec.add_development_dependency "rspec"
25
- spec.add_development_dependency "pry"
26
- spec.add_development_dependency "rake-compiler"
22
+ spec.add_development_dependency 'bundler', '~> 1.6'
23
+ spec.add_development_dependency 'rake'
24
+ spec.add_development_dependency 'rspec'
25
+ spec.add_development_dependency 'pry'
26
+ spec.add_development_dependency 'rake-compiler'
27
+ spec.add_development_dependency 'rspec-its'
28
+ spec.add_development_dependency 'guard'
29
+ spec.add_development_dependency 'guard-rspec'
30
+ spec.add_development_dependency 'guard-rake'
31
+ spec.add_development_dependency 'guard-rubocop'
27
32
  end
@@ -2,6 +2,7 @@ require 'tempfile'
2
2
  require 'jpeg/version'
3
3
  require 'jpeg/jpeg'
4
4
  require 'jpeg/image'
5
+ require 'jpeg/color'
5
6
 
6
7
  module Jpeg
7
8
  def self.open_buffer(str)
@@ -0,0 +1,16 @@
1
+ module Jpeg
2
+ Color = Struct.new(:r, :g, :b) do
3
+ def rgb
4
+ [r, g, b]
5
+ end
6
+ alias_method :to_a, :rgb
7
+
8
+ def to_s
9
+ format '#%02x%02x%02x', *rgb
10
+ end
11
+
12
+ def inspect
13
+ format '<Jpeg::Color r=0x%02x g=0x%02x b=0x%02x>', *rgb
14
+ end
15
+ end
16
+ end
@@ -1,11 +1,24 @@
1
1
  module Jpeg
2
2
  class Image
3
+ def at(x, y)
4
+ raise 'invalid position' unless inside? x, y
5
+ dot = raw_data[y][x]
6
+ color? ? Color.new(*dot) : Color.new(dot, dot, dot)
7
+ end
8
+
3
9
  def rgb?
4
10
  color_info == :rgb
5
11
  end
12
+ alias color? rgb?
6
13
 
7
14
  def gray?
8
15
  color_info == :gray
9
16
  end
17
+
18
+ private
19
+
20
+ def inside?(x, y)
21
+ x < width && x >= 0 && y < height && y >= 0
22
+ end
10
23
  end
11
24
  end
@@ -1,3 +1,3 @@
1
1
  module Jpeg
2
- VERSION = '0.7.0'
2
+ VERSION = '0.7.1'.freeze
3
3
  end
@@ -0,0 +1,9 @@
1
+ describe Jpeg::Color do
2
+ let(:g) { 0x00 }
3
+ let(:rgb) { [0xcc, g, 0xff] }
4
+ subject { Jpeg::Color.new(*rgb) }
5
+
6
+ its(:g) { is_expected.to eq g }
7
+ its(:rgb) { is_expected.to eq rgb }
8
+ its(:to_s) { is_expected.to eq '#cc00ff' }
9
+ end
@@ -0,0 +1,53 @@
1
+ describe Jpeg::Image do
2
+ subject(:image) { Jpeg.open(sample_file_path('zoi.jpg')) }
3
+ its(:width) { is_expected.to eq 630 }
4
+ its(:height) { is_expected.to eq 427 }
5
+
6
+ describe '#inside?' do
7
+ subject { image.send(:inside?, *pos) }
8
+ context [0, 0] do
9
+ let(:pos) { [0, 0] }
10
+ it { is_expected.to eq true }
11
+ end
12
+
13
+ context [629, 426] do
14
+ let(:pos) { [629, 426] }
15
+ it { is_expected.to eq true }
16
+ end
17
+
18
+ [[630, 0], [-1, 0], [0, 427], [0, -1]].each do |pos|
19
+ context pos do
20
+ let(:pos) { pos }
21
+ it { is_expected.to eq false }
22
+ end
23
+ end
24
+ end
25
+
26
+ context 'color image' do
27
+ subject { image }
28
+ it { is_expected.to be_rgb }
29
+ it { is_expected.to be_color }
30
+ it { is_expected.not_to be_gray }
31
+
32
+ describe '#at' do
33
+ subject { image.at(450, 200) }
34
+ it { is_expected.to be_a Jpeg::Color }
35
+ its(:rgb) { is_expected.to eq [0x99, 0x86, 0xbe] }
36
+ context 'invalid position' do
37
+ it { expect { image.at(630, 0) }.to raise_error 'invalid position' }
38
+ end
39
+ end
40
+ end
41
+
42
+ context 'gray image' do
43
+ subject(:image) { Jpeg.open(sample_file_path('gray.jpg')) }
44
+ it { is_expected.to be_gray }
45
+ it { is_expected.not_to be_color }
46
+
47
+ describe '#at' do
48
+ subject { image.at(50, 60) }
49
+ it { is_expected.to be_a Jpeg::Color }
50
+ its(:to_a) { is_expected.to eq [37, 37, 37] }
51
+ end
52
+ end
53
+ end
@@ -1,22 +1,18 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ describe 'Jpeg' do
2
+ describe '.open' do
3
+ subject(:image) { Jpeg.open(sample_file_path(filename)) }
4
+ context 'valid jpeg' do
5
+ let(:filename) { 'sample.jpg' }
2
6
 
3
- def sample_file_path(file)
4
- File.join(File.dirname(__FILE__), 'samples', file)
5
- end
7
+ it { is_expected.to be_a Jpeg::Image }
8
+ its(:size) { is_expected.to eq [112, 112] }
9
+ its(:width) { is_expected.to eq 112 }
10
+ its(:height) { is_expected.to eq 112 }
11
+ its(:color_info) { is_expected.to eq :rgb }
12
+ it { is_expected.to be_rgb }
13
+ it { is_expected.not_to be_gray }
6
14
 
7
- describe "Jpeg" do
8
- subject { @jpeg }
9
- describe :open do
10
- context "valid jpeg" do
11
- before { @jpeg = Jpeg.open(sample_file_path("sample.jpg")) }
12
- it { expect(subject).to be_a Jpeg::Image }
13
- it { expect(subject.size).to eq [112, 112] }
14
- it { expect(subject.width).to eq 112 }
15
- it { expect(subject.height).to eq 112 }
16
- it { expect(subject.color_info).to eq :rgb }
17
- it { expect(subject).to be_rgb }
18
- it { expect(subject).not_to be_gray }
19
- it "should export the decoded data" do
15
+ it 'should export the decoded data' do
20
16
  decoded = subject.raw_data
21
17
  expect(decoded.count).to eq 112
22
18
  expect(decoded[0].count).to eq 112
@@ -26,16 +22,19 @@ describe "Jpeg" do
26
22
  end
27
23
  end
28
24
 
29
- context "non-exists file" do
30
- it { expect { Jpeg.open(sample_file_path("nonexists.jpg")) }.to raise_error(Jpeg::Error) }
25
+ context 'non-exists file' do
26
+ let(:filename) { 'nonexists.jpg' }
27
+ it { expect { subject }.to raise_error(Jpeg::Error) }
31
28
  end
32
29
 
33
- context "not a correct jpeg file" do
34
- it { expect { Jpeg.open(sample_file_path("sample.png")) }.to raise_error(Jpeg::Error) }
30
+ context 'not a correct jpeg file' do
31
+ let(:filename) { 'sample.png' }
32
+ it { expect { subject }.to raise_error(Jpeg::Error) }
35
33
  end
36
34
  end
37
35
  describe :from_string do
38
- before { @jpeg = Jpeg.open_buffer(File.open(sample_file_path("sample.jpg")).read) }
39
- it { expect(subject.size).to eq [112, 112] }
36
+ subject { Jpeg.open_buffer(File.read(sample_file_path(filename))) }
37
+ let(:filename) { 'sample.jpg' }
38
+ its(:size) { is_expected.to eq [112, 112] }
40
39
  end
41
40
  end
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $:.unshift File.expand_path('../lib', File.dirname(__FILE__))
3
+ $LOAD_PATH.unshift File.expand_path('../lib', File.dirname(__FILE__))
4
4
  require 'jpeg'
5
5
 
6
6
  puts Process.pid
Binary file
Binary file
@@ -1,3 +1,8 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
2
  require 'jpeg'
3
3
  require 'pry'
4
+ require 'rspec/its'
5
+
6
+ def sample_file_path(file)
7
+ File.join(File.dirname(__FILE__), 'samples', file)
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jpeg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - masarakki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-07 00:00:00.000000000 Z
11
+ date: 2017-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,76 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-its
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard-rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard-rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: guard-rubocop
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
83
153
  description: libjpeg wrapper for ruby
84
154
  email:
85
155
  - masaki@hisme.net
@@ -90,8 +160,10 @@ extra_rdoc_files: []
90
160
  files:
91
161
  - ".gitignore"
92
162
  - ".rspec"
163
+ - ".rubocop.yml"
93
164
  - ".travis.yml"
94
165
  - Gemfile
166
+ - Guardfile
95
167
  - LICENSE.txt
96
168
  - README.md
97
169
  - Rakefile
@@ -104,12 +176,17 @@ files:
104
176
  - ext/jpeg/jpeg_image.h
105
177
  - jpeg.gemspec
106
178
  - lib/jpeg.rb
179
+ - lib/jpeg/color.rb
107
180
  - lib/jpeg/image.rb
108
181
  - lib/jpeg/version.rb
182
+ - spec/jpeg/color_spec.rb
183
+ - spec/jpeg/image_spec.rb
109
184
  - spec/jpeg_spec.rb
110
185
  - spec/leak_test.rb
186
+ - spec/samples/gray.jpg
111
187
  - spec/samples/sample.jpg
112
188
  - spec/samples/sample.png
189
+ - spec/samples/zoi.jpg
113
190
  - spec/spec_helper.rb
114
191
  homepage: http://github.com/masarakki/jpeg
115
192
  licenses:
@@ -131,13 +208,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
208
  version: '0'
132
209
  requirements: []
133
210
  rubyforge_project:
134
- rubygems_version: 2.2.2
211
+ rubygems_version: 2.6.8
135
212
  signing_key:
136
213
  specification_version: 4
137
214
  summary: libjpeg wrapper for ruby
138
215
  test_files:
216
+ - spec/jpeg/color_spec.rb
217
+ - spec/jpeg/image_spec.rb
139
218
  - spec/jpeg_spec.rb
140
219
  - spec/leak_test.rb
220
+ - spec/samples/gray.jpg
141
221
  - spec/samples/sample.jpg
142
222
  - spec/samples/sample.png
223
+ - spec/samples/zoi.jpg
143
224
  - spec/spec_helper.rb