jpeg 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +31 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +28 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/ext/extconf.rb +6 -0
- data/ext/jpeg.c +6 -0
- data/ext/jpeg.h +8 -0
- data/ext/jpeg_jpeg.c +115 -0
- data/ext/jpeg_jpeg.h +14 -0
- data/spec/jpeg_spec.rb +7 -0
- data/spec/spec_helper.rb +12 -0
- metadata +130 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rspec"
|
10
|
+
gem "rdoc"
|
11
|
+
gem "bundler"
|
12
|
+
gem "jeweler"
|
13
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.8.3)
|
7
|
+
bundler (~> 1.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
rdoc
|
11
|
+
json (1.6.6)
|
12
|
+
rake (0.9.2.2)
|
13
|
+
rdoc (3.12)
|
14
|
+
json (~> 1.4)
|
15
|
+
rspec (2.9.0)
|
16
|
+
rspec-core (~> 2.9.0)
|
17
|
+
rspec-expectations (~> 2.9.0)
|
18
|
+
rspec-mocks (~> 2.9.0)
|
19
|
+
rspec-core (2.9.0)
|
20
|
+
rspec-expectations (2.9.0)
|
21
|
+
diff-lcs (~> 1.1.3)
|
22
|
+
rspec-mocks (2.9.0)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
bundler
|
29
|
+
jeweler
|
30
|
+
rdoc
|
31
|
+
rspec
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Yamada Masaki
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
= jpeg
|
2
|
+
A libjpeg wrapper for ruby
|
3
|
+
== Install
|
4
|
+
gem install jpeg
|
5
|
+
|
6
|
+
or
|
7
|
+
echo 'gem "jpeg"' > Gemfile
|
8
|
+
bundle install
|
9
|
+
|
10
|
+
== Usage
|
11
|
+
jpeg = Jpeg.open('path/to/file')
|
12
|
+
jpeg.size # => [1920, 1080]
|
13
|
+
|
14
|
+
== Contributing to jpeg
|
15
|
+
|
16
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
17
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
18
|
+
* Fork the project.
|
19
|
+
* Start a feature/bugfix branch.
|
20
|
+
* Commit and push until you are happy with your contribution.
|
21
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
22
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
23
|
+
|
24
|
+
== Copyright
|
25
|
+
|
26
|
+
Copyright (c) 2012 Yamada Masaki. See LICENSE.txt for
|
27
|
+
further details.
|
28
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "jpeg"
|
18
|
+
gem.homepage = "http://github.com/masarakki/jpeg"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{libjpeg wrapper for ruby}
|
21
|
+
gem.description = %Q{libjpeg wrapper for ruby}
|
22
|
+
gem.email = "masaki@hisme.net"
|
23
|
+
gem.authors = ["masarakki"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "jpeg #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
data/ext/extconf.rb
ADDED
data/ext/jpeg.c
ADDED
data/ext/jpeg.h
ADDED
data/ext/jpeg_jpeg.c
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
#include <stdio.h>
|
2
|
+
#include <jpeglib.h>
|
3
|
+
#include "jpeg_jpeg.h"
|
4
|
+
|
5
|
+
VALUE Jpeg;
|
6
|
+
|
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
|
+
static VALUE jpeg_jpeg_alloc(VALUE klass);
|
10
|
+
static void jpeg_jpeg_mark(struct jpeg_jpeg *p);
|
11
|
+
static void jpeg_jpeg_free(struct jpeg_jpeg *p);
|
12
|
+
static VALUE jpeg_jpeg_width(VALUE self);
|
13
|
+
static VALUE jpeg_jpeg_height(VALUE self);
|
14
|
+
static VALUE jpeg_jpeg_size(VALUE self);
|
15
|
+
|
16
|
+
void Init_jpeg_jpeg() {
|
17
|
+
Jpeg = rb_define_class("Jpeg", rb_cObject);
|
18
|
+
rb_define_alloc_func(Jpeg, jpeg_jpeg_alloc);
|
19
|
+
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
|
+
rb_define_method(Jpeg, "width", jpeg_jpeg_width, 0);
|
22
|
+
rb_define_method(Jpeg, "height", jpeg_jpeg_height, 0);
|
23
|
+
rb_define_method(Jpeg, "size", jpeg_jpeg_size, 0);
|
24
|
+
}
|
25
|
+
|
26
|
+
static VALUE jpeg_jpeg_alloc(VALUE klass) {
|
27
|
+
struct jpeg_jpeg *jpeg = ALLOC(struct jpeg_jpeg);
|
28
|
+
|
29
|
+
jpeg->read = (void *)ALLOC(struct jpeg_decompress_struct);
|
30
|
+
jpeg->error = (void *)ALLOC(struct jpeg_error_mgr);
|
31
|
+
jpeg->read->err = jpeg_std_error(jpeg->error);
|
32
|
+
jpeg_create_decompress(jpeg->read);
|
33
|
+
|
34
|
+
return Data_Wrap_Struct(klass, jpeg_jpeg_mark, jpeg_jpeg_free, jpeg);
|
35
|
+
}
|
36
|
+
|
37
|
+
static void jpeg_jpeg_mark(struct jpeg_jpeg *p) {
|
38
|
+
|
39
|
+
}
|
40
|
+
|
41
|
+
static void jpeg_jpeg_free(struct jpeg_jpeg *p) {
|
42
|
+
// if (p->read) {
|
43
|
+
// jpeg_destroy_compress(p->read);
|
44
|
+
// free(p->read);
|
45
|
+
//}
|
46
|
+
//xfree(p);
|
47
|
+
}
|
48
|
+
|
49
|
+
static VALUE jpeg_jpeg_s_open(int argc, VALUE *argv, VALUE self) {
|
50
|
+
VALUE path;
|
51
|
+
VALUE jpeg;
|
52
|
+
struct jpeg_jpeg *p_jpeg;
|
53
|
+
int errorp;
|
54
|
+
FILE *fp;
|
55
|
+
rb_scan_args(argc, argv, "1", &path);
|
56
|
+
Check_Type(path, T_STRING);
|
57
|
+
|
58
|
+
jpeg = rb_funcall(Jpeg, rb_intern("new"), 0);
|
59
|
+
Data_Get_Struct(jpeg, struct jpeg_jpeg, p_jpeg);
|
60
|
+
|
61
|
+
fp = fopen(RSTRING_PTR(path), "rb");
|
62
|
+
jpeg_stdio_src(p_jpeg->read, fp);
|
63
|
+
jpeg_read_header(p_jpeg->read, TRUE);
|
64
|
+
jpeg_start_decompress(p_jpeg->read);
|
65
|
+
fclose(fp);
|
66
|
+
return jpeg;
|
67
|
+
}
|
68
|
+
|
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
|
+
static VALUE jpeg_jpeg_width(VALUE self) {
|
94
|
+
struct jpeg_jpeg *p_jpeg;
|
95
|
+
Data_Get_Struct(self, struct jpeg_jpeg, p_jpeg);
|
96
|
+
return rb_int_new(p_jpeg->read->output_width);
|
97
|
+
}
|
98
|
+
|
99
|
+
static VALUE jpeg_jpeg_height(VALUE self) {
|
100
|
+
struct jpeg_jpeg *p_jpeg;
|
101
|
+
Data_Get_Struct(self, struct jpeg_jpeg, p_jpeg);
|
102
|
+
return rb_int_new(p_jpeg->read->output_height);
|
103
|
+
}
|
104
|
+
|
105
|
+
static VALUE jpeg_jpeg_size(VALUE self) {
|
106
|
+
struct jpeg_jpeg *p_jpeg;
|
107
|
+
VALUE array;
|
108
|
+
Data_Get_Struct(self, struct jpeg_jpeg, p_jpeg);
|
109
|
+
|
110
|
+
array = rb_ary_new();
|
111
|
+
rb_ary_push(array, rb_int_new(p_jpeg->read->output_width));
|
112
|
+
rb_ary_push(array, rb_int_new(p_jpeg->read->output_height));
|
113
|
+
|
114
|
+
return array;
|
115
|
+
}
|
data/ext/jpeg_jpeg.h
ADDED
data/spec/jpeg_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'jpeg'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jpeg
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- masarakki
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rdoc
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: jeweler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: libjpeg wrapper for ruby
|
79
|
+
email: masaki@hisme.net
|
80
|
+
executables: []
|
81
|
+
extensions:
|
82
|
+
- ext/extconf.rb
|
83
|
+
extra_rdoc_files:
|
84
|
+
- LICENSE.txt
|
85
|
+
- README.rdoc
|
86
|
+
files:
|
87
|
+
- .document
|
88
|
+
- .rspec
|
89
|
+
- Gemfile
|
90
|
+
- Gemfile.lock
|
91
|
+
- LICENSE.txt
|
92
|
+
- README.rdoc
|
93
|
+
- Rakefile
|
94
|
+
- VERSION
|
95
|
+
- ext/extconf.rb
|
96
|
+
- ext/jpeg.c
|
97
|
+
- ext/jpeg.h
|
98
|
+
- ext/jpeg_jpeg.c
|
99
|
+
- ext/jpeg_jpeg.h
|
100
|
+
- spec/jpeg_spec.rb
|
101
|
+
- spec/spec_helper.rb
|
102
|
+
homepage: http://github.com/masarakki/jpeg
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ! '>='
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
segments:
|
116
|
+
- 0
|
117
|
+
hash: 1223134826035652440
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
120
|
+
requirements:
|
121
|
+
- - ! '>='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 1.8.21
|
127
|
+
signing_key:
|
128
|
+
specification_version: 3
|
129
|
+
summary: libjpeg wrapper for ruby
|
130
|
+
test_files: []
|