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 +4 -4
- data/.rspec +2 -0
- data/.rubocop.yml +2 -0
- data/.travis.yml +4 -3
- data/Guardfile +25 -0
- data/README.md +5 -0
- data/Rakefile +5 -5
- data/ext/jpeg/extconf.rb +2 -4
- data/ext/jpeg/jpeg_image.c +1 -1
- data/jpeg.gemspec +19 -14
- data/lib/jpeg.rb +1 -0
- data/lib/jpeg/color.rb +16 -0
- data/lib/jpeg/image.rb +13 -0
- data/lib/jpeg/version.rb +1 -1
- data/spec/jpeg/color_spec.rb +9 -0
- data/spec/jpeg/image_spec.rb +53 -0
- data/spec/jpeg_spec.rb +22 -23
- data/spec/leak_test.rb +1 -1
- data/spec/samples/gray.jpg +0 -0
- data/spec/samples/zoi.jpg +0 -0
- data/spec/spec_helper.rb +5 -0
- metadata +84 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93785b2c60448a6fa4e9bf5b69de642d1ba0099e
|
4
|
+
data.tar.gz: 31ae30b5e411487c1c3d4436a6496a9dc2cdbd8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc3ba62f9d815a63e620c86a95cc7ca12b0c1e2c4f8ab78bf505e38988b8ecf700a699fe47e6f39ac27a1bede8f9eff79d12ca3e4331dd7a9965bd54623e00b8
|
7
|
+
data.tar.gz: 4cb12a28680e11496716f216d0aa355ac269cf68e012078ede2895b7bfd1beb336b3edaf3dec42c4206a02b2c9b1fb7705a35bcc4ee524bed40bdbc6f586a824
|
data/.rspec
CHANGED
data/.rubocop.yml
ADDED
data/.travis.yml
CHANGED
data/Guardfile
ADDED
@@ -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
|
2
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
3
|
|
4
4
|
RSpec::Core::RakeTask.new(:spec)
|
5
5
|
|
6
|
-
task :
|
6
|
+
task default: :spec
|
7
7
|
|
8
8
|
require 'rake/extensiontask'
|
9
9
|
|
10
|
-
Rake::ExtensionTask.new(
|
11
|
-
ext.lib_dir =
|
10
|
+
Rake::ExtensionTask.new('jpeg') do |ext|
|
11
|
+
ext.lib_dir = 'lib/jpeg'
|
12
12
|
end
|
data/ext/jpeg/extconf.rb
CHANGED
data/ext/jpeg/jpeg_image.c
CHANGED
@@ -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
|
-
#
|
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) {
|
data/jpeg.gemspec
CHANGED
@@ -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 =
|
7
|
+
spec.name = 'jpeg'
|
8
8
|
spec.version = Jpeg::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.extensions = [
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
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 = [
|
20
|
+
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
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
|
data/lib/jpeg.rb
CHANGED
data/lib/jpeg/color.rb
ADDED
@@ -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
|
data/lib/jpeg/image.rb
CHANGED
@@ -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
|
data/lib/jpeg/version.rb
CHANGED
@@ -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
|
data/spec/jpeg_spec.rb
CHANGED
@@ -1,22 +1,18 @@
|
|
1
|
-
|
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
|
-
|
4
|
-
|
5
|
-
|
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
|
-
|
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
|
30
|
-
|
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
|
34
|
-
|
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
|
-
|
39
|
-
|
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
|
data/spec/leak_test.rb
CHANGED
Binary file
|
Binary file
|
data/spec/spec_helper.rb
CHANGED
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.
|
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:
|
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.
|
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
|