image-file 0.1.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.
- data/.autotest +16 -0
- data/.document +3 -0
- data/.gitignore +2 -0
- data/.rspec +1 -0
- data/Gemfile +10 -0
- data/History.markdown +13 -0
- data/License.txt +23 -0
- data/README.markdown +4 -0
- data/Rakefile +14 -0
- data/autotest/discover.rb +1 -0
- data/examples/pdf.rb +15 -0
- data/ext/image_file/depend +7 -0
- data/ext/image_file/extconf.rb +25 -0
- data/ext/image_file/image.c +411 -0
- data/ext/image_file/image_file.c +12 -0
- data/ext/image_file/internal.h +79 -0
- data/ext/image_file/jpeg_reader.c +938 -0
- data/image-file.gemspec +25 -0
- data/lib/.gitignore +3 -0
- data/lib/image_file/version.rb +8 -0
- data/pkg/.gitignore +2 -0
- data/spec/image_file/image_spec.rb +48 -0
- data/spec/image_file/jpeg_reader_spec.rb +115 -0
- data/spec/image_file_spec.rb +15 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/support/recompile_cat.jpg +0 -0
- data/spec/support/recompile_cat.png +0 -0
- data/spec/support/recompile_cat_CMYK.jpg +0 -0
- data/tmp/.gitignore +2 -0
- metadata +100 -0
data/image-file.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
4
|
+
require 'image_file/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'image-file'
|
8
|
+
s.version = ImageFile::Version::STRING
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.authors = ['Kenta Murata']
|
11
|
+
s.email = 'mrkn@mrkn.jp'
|
12
|
+
s.homepage = 'http://github.com/mrkn/image-file'
|
13
|
+
s.summary = "image-file-#{ImageFile::Version::STRING}"
|
14
|
+
s.description = 'A library for handling image files'
|
15
|
+
|
16
|
+
s.rubygems_version = '1.3.7'
|
17
|
+
#s.rubyforge_project = 'image-file'
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map {|f| File.basename(f) }
|
22
|
+
s.extra_rdoc_files = []
|
23
|
+
s.rdoc_options = ['--charset=UTF-8']
|
24
|
+
s.require_path = 'lib'
|
25
|
+
end
|
data/lib/.gitignore
ADDED
data/pkg/.gitignore
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module ImageFile
|
4
|
+
describe Image, ".new" do
|
5
|
+
it "should raise ArgumentError without pixel format" do
|
6
|
+
expect {
|
7
|
+
described_class.new(width:42, height:42)
|
8
|
+
}.to raise_error(ArgumentError)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should raise ArgumentError without width" do
|
12
|
+
expect {
|
13
|
+
described_class.new(pixel_format: :RGB24, height:42)
|
14
|
+
}.to raise_error(ArgumentError)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should raise ArgumentError without height" do
|
18
|
+
expect {
|
19
|
+
described_class.new(pixel_format: :RGB24, width:42)
|
20
|
+
}.to raise_error(ArgumentError)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe Image do
|
25
|
+
subject { Image.new(width:42, height:42, pixel_format: :RGB24) }
|
26
|
+
|
27
|
+
its(:width) { should be == 42 }
|
28
|
+
its(:height) { should be == 42 }
|
29
|
+
its(:row_stride) { should be == 42 }
|
30
|
+
its(:pixel_format) { should be == :RGB24 }
|
31
|
+
|
32
|
+
describe "create_cairo_surface" do
|
33
|
+
subject { Image.new(width:42, height:42, pixel_format: :RGB24).create_cairo_surface }
|
34
|
+
it { should be_a(Cairo::Surface) }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe Image, "with row-stride" do
|
39
|
+
subject { Image.new(width:42, height:42, pixel_format: :RGB24, row_stride:64) }
|
40
|
+
|
41
|
+
its(:width) { should be == 42 }
|
42
|
+
its(:height) { should be == 42 }
|
43
|
+
its(:row_stride) { should be == 64 }
|
44
|
+
its(:pixel_format) { should be == :RGB24 }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# vim: foldmethod=marker
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RECOMPILE_CAT_JPG = File.expand_path(File.join('support', 'recompile_cat.jpg'), SPEC_DIR).freeze
|
4
|
+
RECOMPILE_CAT_CMYK_JPG = File.expand_path(File.join('support', 'recompile_cat_CMYK.jpg'), SPEC_DIR).freeze
|
5
|
+
RECOMPILE_CAT_PNG = RECOMPILE_CAT_JPG.sub(/\.jpg\Z/, '.png').freeze
|
6
|
+
|
7
|
+
module ImageFile
|
8
|
+
describe JpegReader do
|
9
|
+
context "created by open" do
|
10
|
+
subject { described_class.open(RECOMPILE_CAT_JPG) }
|
11
|
+
it { should be_source_will_be_closed }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe JpegReader, "for 'recompile_cat.jpg'" do #{{{
|
16
|
+
subject { described_class.open(RECOMPILE_CAT_JPG) }
|
17
|
+
|
18
|
+
its(:image_width) { should be == 500 }
|
19
|
+
its(:image_height) { should be == 300 }
|
20
|
+
its(:num_components) { should be == 3 }
|
21
|
+
its(:jpeg_color_space) { should be == :YCbCr }
|
22
|
+
|
23
|
+
its(:out_color_space) { should be == :RGB }
|
24
|
+
its(:scale) { should be == 1 }
|
25
|
+
its(:output_gamma) { should be == 1 }
|
26
|
+
it { should_not be_buffered_image }
|
27
|
+
its(:dct_method) { should be == :ISLOW }
|
28
|
+
it { should_not be_quantize_colors }
|
29
|
+
its(:dither_mode) { should be == :FS }
|
30
|
+
|
31
|
+
its(:output_width) { should be == 500 }
|
32
|
+
its(:output_height) { should be == 300 }
|
33
|
+
its(:output_components) { should be == 3 }
|
34
|
+
|
35
|
+
context "with scale of 1/2" do
|
36
|
+
before { subject.scale = 1.quo(2) }
|
37
|
+
its(:output_width) { should be == 250 }
|
38
|
+
its(:output_height) { should be == 150 }
|
39
|
+
end
|
40
|
+
|
41
|
+
context "after setting output_gamma to 1.2" do
|
42
|
+
before { subject.output_gamma = 1.2 }
|
43
|
+
its(:output_gamma) { should be == 1.2 }
|
44
|
+
end
|
45
|
+
|
46
|
+
describe :read_image do
|
47
|
+
subject { described_class.open(RECOMPILE_CAT_JPG).read_image }
|
48
|
+
its(:width) { should be == 500 }
|
49
|
+
its(:height) { should be == 300 }
|
50
|
+
its(:row_stride) { should be == 500 }
|
51
|
+
its(:pixel_format) { should be == :RGB24 }
|
52
|
+
end
|
53
|
+
|
54
|
+
describe :read_image, "with row_stride:42 (< width)" do
|
55
|
+
subject { described_class.open(RECOMPILE_CAT_JPG).read_image(row_stride:42) }
|
56
|
+
its(:row_stride) { should be == 500 }
|
57
|
+
end
|
58
|
+
|
59
|
+
describe :read_image, "with row_stride:512 (> width)" do
|
60
|
+
subject { described_class.open(RECOMPILE_CAT_JPG).read_image(row_stride:512) }
|
61
|
+
its(:row_stride) { should be == 512 }
|
62
|
+
end
|
63
|
+
|
64
|
+
describe :read_image, "with pixel_format: :ARGB32" do
|
65
|
+
subject { described_class.open(RECOMPILE_CAT_JPG).read_image(pixel_format: :ARGB32) }
|
66
|
+
its(:pixel_format) { should be == :ARGB32 }
|
67
|
+
end
|
68
|
+
|
69
|
+
describe :read_image, "with pixel_format: :xyzzy" do
|
70
|
+
subject { described_class.open(RECOMPILE_CAT_JPG).read_image(pixel_format: :xyzzy) }
|
71
|
+
its(:pixel_format) { should be == :RGB24 }
|
72
|
+
end
|
73
|
+
end #}}}
|
74
|
+
|
75
|
+
describe JpegReader, "for 'recompile_cat_CMYK.jpg'" do #{{{
|
76
|
+
subject { described_class.open(RECOMPILE_CAT_CMYK_JPG) }
|
77
|
+
its(:num_components) { should be == 4 }
|
78
|
+
its(:jpeg_color_space) { should be == :CMYK }
|
79
|
+
its(:out_color_space) { should be == :CMYK }
|
80
|
+
|
81
|
+
describe :read_image do
|
82
|
+
subject { described_class.open(RECOMPILE_CAT_CMYK_JPG).read_image }
|
83
|
+
its(:width) { should be == 500 }
|
84
|
+
its(:height) { should be == 300 }
|
85
|
+
its(:row_stride) { should be == 500 }
|
86
|
+
its(:pixel_format) { should be == :RGB24 }
|
87
|
+
end
|
88
|
+
end #}}}
|
89
|
+
|
90
|
+
describe JpegReader, "for 'recompile_cat.png'" do #{{{
|
91
|
+
subject { described_class.open(RECOMPILE_CAT_PNG) }
|
92
|
+
|
93
|
+
describe :image_width do
|
94
|
+
it { expect { subject.image_width }.to raise_error(described_class::Error) }
|
95
|
+
end
|
96
|
+
|
97
|
+
describe :image_height do
|
98
|
+
it { expect { subject.image_height }.to raise_error(described_class::Error) }
|
99
|
+
end
|
100
|
+
|
101
|
+
describe :num_components do
|
102
|
+
it { expect { subject.num_components }.to raise_error(described_class::Error) }
|
103
|
+
end
|
104
|
+
|
105
|
+
describe :jpeg_color_space do
|
106
|
+
it { expect { subject.jpeg_color_space }.to raise_error(described_class::Error) }
|
107
|
+
end
|
108
|
+
|
109
|
+
describe :read_image do
|
110
|
+
it { expect { subject.read_image }.to raise_error(described_class::Error) }
|
111
|
+
end
|
112
|
+
end #}}}
|
113
|
+
end
|
114
|
+
|
115
|
+
# vim: foldmethod=marker
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "ImageFile module" do
|
4
|
+
it "should exists" do
|
5
|
+
expect { ImageFile }.to_not raise_error(NameError)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module ImageFile
|
10
|
+
describe "Image class" do
|
11
|
+
it "should exists" do
|
12
|
+
expect { Image }.to_not raise_error(NameError)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
SPEC_DIR = File.expand_path('..', __FILE__)
|
2
|
+
|
3
|
+
Dir['spec/support/**/*.rb'].map {|f| require_relative f }
|
4
|
+
|
5
|
+
def in_editor?
|
6
|
+
%w[VIM EMACS TM_MODE].any? {|var| ENV.has_key?(var) }
|
7
|
+
end
|
8
|
+
|
9
|
+
RSpec.configure do |c|
|
10
|
+
c.color_enabled = !in_editor?
|
11
|
+
c.filter_run(focused:true)
|
12
|
+
c.run_all_when_everything_filtered = true
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'image_file'
|
16
|
+
require 'cairo'
|
Binary file
|
Binary file
|
Binary file
|
data/tmp/.gitignore
ADDED
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: image-file
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Kenta Murata
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-12-17 00:00:00 +09:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: A library for handling image files
|
22
|
+
email: mrkn@mrkn.jp
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- .autotest
|
31
|
+
- .document
|
32
|
+
- .gitignore
|
33
|
+
- .rspec
|
34
|
+
- Gemfile
|
35
|
+
- History.markdown
|
36
|
+
- License.txt
|
37
|
+
- README.markdown
|
38
|
+
- Rakefile
|
39
|
+
- autotest/discover.rb
|
40
|
+
- examples/pdf.rb
|
41
|
+
- ext/image_file/depend
|
42
|
+
- ext/image_file/extconf.rb
|
43
|
+
- ext/image_file/image.c
|
44
|
+
- ext/image_file/image_file.c
|
45
|
+
- ext/image_file/internal.h
|
46
|
+
- ext/image_file/jpeg_reader.c
|
47
|
+
- image-file.gemspec
|
48
|
+
- lib/.gitignore
|
49
|
+
- lib/image_file/version.rb
|
50
|
+
- pkg/.gitignore
|
51
|
+
- spec/image_file/image_spec.rb
|
52
|
+
- spec/image_file/jpeg_reader_spec.rb
|
53
|
+
- spec/image_file_spec.rb
|
54
|
+
- spec/spec_helper.rb
|
55
|
+
- spec/support/recompile_cat.jpg
|
56
|
+
- spec/support/recompile_cat.png
|
57
|
+
- spec/support/recompile_cat_CMYK.jpg
|
58
|
+
- tmp/.gitignore
|
59
|
+
has_rdoc: true
|
60
|
+
homepage: http://github.com/mrkn/image-file
|
61
|
+
licenses: []
|
62
|
+
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options:
|
65
|
+
- --charset=UTF-8
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 107401639748163987
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
hash: 107401639748163987
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
version: "0"
|
86
|
+
requirements: []
|
87
|
+
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 1.3.7
|
90
|
+
signing_key:
|
91
|
+
specification_version: 3
|
92
|
+
summary: image-file-0.1.0
|
93
|
+
test_files:
|
94
|
+
- spec/image_file/image_spec.rb
|
95
|
+
- spec/image_file/jpeg_reader_spec.rb
|
96
|
+
- spec/image_file_spec.rb
|
97
|
+
- spec/spec_helper.rb
|
98
|
+
- spec/support/recompile_cat.jpg
|
99
|
+
- spec/support/recompile_cat.png
|
100
|
+
- spec/support/recompile_cat_CMYK.jpg
|