jpeg 0.0.2 → 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/README.rdoc +2 -2
- data/VERSION +1 -1
- data/ext/jpeg_jpeg.c +11 -32
- data/jpeg.gemspec +67 -0
- data/lib/jpeg.rb +10 -0
- data/spec/jpeg_spec.rb +31 -2
- data/spec/samples/sample.jpg +0 -0
- metadata +6 -3
data/README.rdoc
CHANGED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.0
|
|
1
|
+
0.1.0
|
data/ext/jpeg_jpeg.c
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
VALUE Jpeg;
|
|
6
6
|
|
|
7
7
|
static VALUE jpeg_jpeg_s_open(int argc, VALUE *argv, VALUE sef);
|
|
8
|
-
static VALUE jpeg_jpeg_s_open_buffer(int argc, VALUE *argv, VALUE sef);
|
|
9
8
|
static VALUE jpeg_jpeg_alloc(VALUE klass);
|
|
10
9
|
static void jpeg_jpeg_mark(struct jpeg_jpeg *p);
|
|
11
10
|
static void jpeg_jpeg_free(struct jpeg_jpeg *p);
|
|
@@ -17,7 +16,6 @@ void Init_jpeg_jpeg() {
|
|
|
17
16
|
Jpeg = rb_define_class("Jpeg", rb_cObject);
|
|
18
17
|
rb_define_alloc_func(Jpeg, jpeg_jpeg_alloc);
|
|
19
18
|
rb_define_singleton_method(Jpeg, "open", jpeg_jpeg_s_open, -1);
|
|
20
|
-
rb_define_singleton_method(Jpeg, "open_buffer", jpeg_jpeg_s_open_buffer, -1);
|
|
21
19
|
rb_define_method(Jpeg, "width", jpeg_jpeg_width, 0);
|
|
22
20
|
rb_define_method(Jpeg, "height", jpeg_jpeg_height, 0);
|
|
23
21
|
rb_define_method(Jpeg, "size", jpeg_jpeg_size, 0);
|
|
@@ -39,11 +37,14 @@ static void jpeg_jpeg_mark(struct jpeg_jpeg *p) {
|
|
|
39
37
|
}
|
|
40
38
|
|
|
41
39
|
static void jpeg_jpeg_free(struct jpeg_jpeg *p) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
if (p->read) {
|
|
41
|
+
jpeg_destroy_compress(p->read);
|
|
42
|
+
free(p->read);
|
|
43
|
+
}
|
|
44
|
+
if (p->error) {
|
|
45
|
+
free(p->error);
|
|
46
|
+
}
|
|
47
|
+
xfree(p);
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
static VALUE jpeg_jpeg_s_open(int argc, VALUE *argv, VALUE self) {
|
|
@@ -58,7 +59,9 @@ static VALUE jpeg_jpeg_s_open(int argc, VALUE *argv, VALUE self) {
|
|
|
58
59
|
jpeg = rb_funcall(Jpeg, rb_intern("new"), 0);
|
|
59
60
|
Data_Get_Struct(jpeg, struct jpeg_jpeg, p_jpeg);
|
|
60
61
|
|
|
61
|
-
fp = fopen(RSTRING_PTR(path), "rb")
|
|
62
|
+
if ((fp = fopen(RSTRING_PTR(path), "rb")) == NULL) {
|
|
63
|
+
rb_raise(rb_eRuntimeError, "Open file failed");
|
|
64
|
+
}
|
|
62
65
|
jpeg_stdio_src(p_jpeg->read, fp);
|
|
63
66
|
jpeg_read_header(p_jpeg->read, TRUE);
|
|
64
67
|
jpeg_start_decompress(p_jpeg->read);
|
|
@@ -66,30 +69,6 @@ static VALUE jpeg_jpeg_s_open(int argc, VALUE *argv, VALUE self) {
|
|
|
66
69
|
return jpeg;
|
|
67
70
|
}
|
|
68
71
|
|
|
69
|
-
static VALUE jpeg_jpeg_s_open_buffer(int argc, VALUE *argv, VALUE self) {
|
|
70
|
-
VALUE buffer;
|
|
71
|
-
VALUE jpeg;
|
|
72
|
-
struct jpeg_jpeg *p_jpeg;
|
|
73
|
-
void *data = NULL;
|
|
74
|
-
int len = 0;
|
|
75
|
-
int errorp;
|
|
76
|
-
int buffer_is_temporary = 0;
|
|
77
|
-
|
|
78
|
-
rb_scan_args(argc, argv, "1", &buffer);
|
|
79
|
-
|
|
80
|
-
if (TYPE(buffer) == T_STRING) {
|
|
81
|
-
data = RSTRING_PTR(buffer);
|
|
82
|
-
len = RSTRING_LEN(buffer);
|
|
83
|
-
} else {
|
|
84
|
-
rb_raise(rb_eTypeError, "wrong argument type %s (expected String)", rb_class2name(CLASS_OF(buffer)));
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
jpeg = rb_funcall(Jpeg, rb_intern("new"), 0);
|
|
88
|
-
Data_Get_Struct(jpeg, struct jpeg_jpeg, p_jpeg);
|
|
89
|
-
|
|
90
|
-
return jpeg;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
72
|
static VALUE jpeg_jpeg_width(VALUE self) {
|
|
94
73
|
struct jpeg_jpeg *p_jpeg;
|
|
95
74
|
Data_Get_Struct(self, struct jpeg_jpeg, p_jpeg);
|
data/jpeg.gemspec
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Generated by jeweler
|
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
|
4
|
+
# -*- encoding: utf-8 -*-
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |s|
|
|
7
|
+
s.name = "jpeg"
|
|
8
|
+
s.version = "0.1.0"
|
|
9
|
+
|
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
|
+
s.authors = ["masarakki"]
|
|
12
|
+
s.date = "2012-03-29"
|
|
13
|
+
s.description = "libjpeg wrapper for ruby"
|
|
14
|
+
s.email = "masaki@hisme.net"
|
|
15
|
+
s.extensions = ["ext/extconf.rb"]
|
|
16
|
+
s.extra_rdoc_files = [
|
|
17
|
+
"LICENSE.txt",
|
|
18
|
+
"README.rdoc"
|
|
19
|
+
]
|
|
20
|
+
s.files = [
|
|
21
|
+
".document",
|
|
22
|
+
".rspec",
|
|
23
|
+
"Gemfile",
|
|
24
|
+
"Gemfile.lock",
|
|
25
|
+
"LICENSE.txt",
|
|
26
|
+
"README.rdoc",
|
|
27
|
+
"Rakefile",
|
|
28
|
+
"VERSION",
|
|
29
|
+
"ext/extconf.rb",
|
|
30
|
+
"ext/jpeg.c",
|
|
31
|
+
"ext/jpeg.h",
|
|
32
|
+
"ext/jpeg_jpeg.c",
|
|
33
|
+
"ext/jpeg_jpeg.h",
|
|
34
|
+
"jpeg.gemspec",
|
|
35
|
+
"lib/jpeg.rb",
|
|
36
|
+
"spec/jpeg_spec.rb",
|
|
37
|
+
"spec/samples/sample.jpg",
|
|
38
|
+
"spec/spec_helper.rb"
|
|
39
|
+
]
|
|
40
|
+
s.homepage = "http://github.com/masarakki/jpeg"
|
|
41
|
+
s.licenses = ["MIT"]
|
|
42
|
+
s.require_paths = ["lib"]
|
|
43
|
+
s.rubygems_version = "1.8.21"
|
|
44
|
+
s.summary = "libjpeg wrapper for ruby"
|
|
45
|
+
|
|
46
|
+
if s.respond_to? :specification_version then
|
|
47
|
+
s.specification_version = 3
|
|
48
|
+
|
|
49
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
50
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
|
51
|
+
s.add_development_dependency(%q<rdoc>, [">= 0"])
|
|
52
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
|
53
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
|
54
|
+
else
|
|
55
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
|
56
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
|
57
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
|
58
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
|
59
|
+
end
|
|
60
|
+
else
|
|
61
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
|
62
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
|
63
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
|
64
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
data/lib/jpeg.rb
ADDED
data/spec/jpeg_spec.rb
CHANGED
|
@@ -1,7 +1,36 @@
|
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
2
|
|
|
3
|
+
def sample_file_path(file)
|
|
4
|
+
File.join(File.dirname(__FILE__), 'samples', file)
|
|
5
|
+
end
|
|
6
|
+
|
|
3
7
|
describe "Jpeg" do
|
|
4
|
-
|
|
5
|
-
|
|
8
|
+
subject { @jpeg }
|
|
9
|
+
describe :open do
|
|
10
|
+
context "valid jpeg" do
|
|
11
|
+
before { @jpeg = Jpeg.open(sample_file_path("sample.jpg")) }
|
|
12
|
+
its(:size) { should == [112, 112] }
|
|
13
|
+
its(:width) { should == 112 }
|
|
14
|
+
its(:height) { should == 112 }
|
|
15
|
+
end
|
|
16
|
+
context "non-exists file" do
|
|
17
|
+
it {
|
|
18
|
+
lambda {
|
|
19
|
+
Jpeg.open(sample_file_path("nonexists.jpg"))
|
|
20
|
+
}.should raise_error
|
|
21
|
+
}
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
context "not a correct jpeg file" do
|
|
25
|
+
it {
|
|
26
|
+
lambda {
|
|
27
|
+
Jpeg.open(sample_file_path("sample.png"))
|
|
28
|
+
}.should raise_error
|
|
29
|
+
}
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
describe :from_string do
|
|
33
|
+
before { @jpeg = Jpeg.open_buffer(File.open(sample_file_path("sample.jpg")).read) }
|
|
34
|
+
its(:size) { should == [112, 112] }
|
|
6
35
|
end
|
|
7
36
|
end
|
|
Binary file
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jpeg
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 0.1.0
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2012-03-
|
|
12
|
+
date: 2012-03-29 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rspec
|
|
@@ -97,7 +97,10 @@ files:
|
|
|
97
97
|
- ext/jpeg.h
|
|
98
98
|
- ext/jpeg_jpeg.c
|
|
99
99
|
- ext/jpeg_jpeg.h
|
|
100
|
+
- jpeg.gemspec
|
|
101
|
+
- lib/jpeg.rb
|
|
100
102
|
- spec/jpeg_spec.rb
|
|
103
|
+
- spec/samples/sample.jpg
|
|
101
104
|
- spec/spec_helper.rb
|
|
102
105
|
homepage: http://github.com/masarakki/jpeg
|
|
103
106
|
licenses:
|
|
@@ -114,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
114
117
|
version: '0'
|
|
115
118
|
segments:
|
|
116
119
|
- 0
|
|
117
|
-
hash:
|
|
120
|
+
hash: -2749025185700545883
|
|
118
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
122
|
none: false
|
|
120
123
|
requirements:
|