webp-ffi 0.1.7 → 0.1.8

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: f324acb0231fe4a10343187cd018ae7d09580048
4
- data.tar.gz: e82178d2e5945a9dbc249d46351faa7d1320890a
3
+ metadata.gz: 4faf9be4b898c23d0b6b8c035046f6b659878652
4
+ data.tar.gz: a3a0c25ecca3b5d402a4abac31f8f279a6ee1192
5
5
  SHA512:
6
- metadata.gz: c3b829f324a7154866a68026db7d9074b63ad204c50af0ed0b85da400a7732642c0a9d7fe309ba305e79d1413c9cd65e0d2f90224d202ed724aca4e1446c5703
7
- data.tar.gz: b8c39d2745d5a0b724718f422d3f2fbc3a19a634265cba885e23db10c34e954cb8f7f835b71f16a94270d215e8f0cd374c5c15df77d685f00fd2ab8acb5a5f70
6
+ metadata.gz: d44c413f3e4b72eb08377f179d6a0ada43549d36d5b3baf79ce38e4cb6e03f4ea6245937ea9edb53fd615c7abc5f59aeb873ab7c648c89293a884912d9b79f37
7
+ data.tar.gz: 123198f82ddfe778ab72614696afa54fbf7fb88497d1a4ef1107feb262cdcd4d9d322f008be36f580b5cd192b2dc6eb91fce5d352789f3a077d588ddb1c0b2c0
data/.travis.yml CHANGED
@@ -17,5 +17,6 @@ branches:
17
17
  - development
18
18
  matrix:
19
19
  allow_failures:
20
+ - rvm: rbx-19mode
20
21
  - rvm: ruby-head
21
22
  - rvm: jruby-head
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## v0.1.8
2
+
3
+ * Fix decoder options (it was not working fully)
4
+
1
5
  ## v0.1.7
2
6
 
3
7
  * Bump FFI dependency to ~> 1.9.0
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Webp-ffi
2
2
 
3
- [![Build Status](https://travis-ci.org/le0pard/webp-ffi.png)](https://travis-ci.org/le0pard/webp-ffi)
3
+ [![Build Status](https://travis-ci.org/le0pard/webp-ffi.png)](https://travis-ci.org/le0pard/webp-ffi)
4
4
  [![Code Climate](https://codeclimate.com/github/le0pard/webp-ffi.png)](https://codeclimate.com/github/le0pard/webp-ffi)
5
5
 
6
6
  Ruby wrapper for libwebp. What is WebP?
@@ -17,16 +17,16 @@ First of all you should have install libraries: libpng, libjpeg and libwebp (for
17
17
 
18
18
  For ubuntu, debian:
19
19
 
20
- sudo apt-get install libjpeg62-dev libpng12-dev libtiff4-dev
21
-
20
+ sudo apt-get install libjpeg-dev libpng-dev libtiff-dev
21
+
22
22
  For Mac OS:
23
23
 
24
24
  sudo port install jpeg libpng tiff
25
-
25
+
26
26
  or:
27
27
 
28
28
  brew install libjpg libpng libtiff
29
-
29
+
30
30
  Next, you should [install libwebp](https://developers.google.com/speed/webp/docs/compiling).
31
31
 
32
32
  ### Final part
@@ -51,22 +51,22 @@ Basic info about libwebp (encoder and decoder versions):
51
51
 
52
52
  $ irb
53
53
  2.0.0p0 :001 > require 'webp_ffi'
54
- => true
54
+ => true
55
55
  2.0.0p0 :002 > WebP.decoder_version
56
- => "0.2.0"
56
+ => "0.3.1"
57
57
  2.0.0p0 :003 > WebP.encoder_version
58
- => "0.2.0"
59
-
58
+ => "0.3.1"
59
+
60
60
 
61
61
  ### WebP size (width and height)
62
-
62
+
63
63
  Get size (width and height) from webp image:
64
64
 
65
65
  filename = File.expand_path(File.join(File.dirname(__FILE__), "spec/factories/4.webp"))
66
66
  WebP.webp_size(File.open(filename, "rb").read)
67
67
  => [2000, 2353]
68
-
69
-
68
+
69
+
70
70
  ### Encode WebP image
71
71
 
72
72
  Encode png, jpg or tiff image to webp:
@@ -74,14 +74,14 @@ Encode png, jpg or tiff image to webp:
74
74
  filename = File.expand_path(File.join(File.dirname(__FILE__), "spec/factories/4.png"))
75
75
  out_filename = File.expand_path(File.join(File.dirname(__FILE__), "tmp/4.webp"))
76
76
  WebP.encode(filename, out_filename)
77
-
78
-
77
+
78
+
79
79
  Encode png, jpg or tiff image to webp with options:
80
80
 
81
81
  WebP.encode(filename, out_filename, quality: 50, resize_w: 100, resize_h: 200)
82
82
  WebP.encode(filename, out_filename, quality: 75, crop_x: 0, cropt_y: 0, crop_w: 100, crop_h: 100)
83
-
84
-
83
+
84
+
85
85
  Possible encode options:
86
86
 
87
87
  * **lossless** (int) - Lossless encoding (0=lossy(default), 1=lossless)
@@ -106,7 +106,7 @@ Possible encode options:
106
106
  * **width** (int), **height** (int) - Input size (width x height) for YUV
107
107
  * **crop\_x** (int), **crop\_y** (int), **crop\_w** (int), **crop\_h** (int) - crop picture with the given rectangle
108
108
  * **resize\_w** (int), **resize\_h** (int) - resize picture (after any cropping)
109
-
109
+
110
110
  ### Decode WebP image
111
111
 
112
112
  Decode webp image (default format is png):
@@ -114,8 +114,8 @@ Decode webp image (default format is png):
114
114
  filename = File.expand_path(File.join(File.dirname(__FILE__), "spec/factories/4.webp"))
115
115
  out_filename = File.expand_path(File.join(File.dirname(__FILE__), "tmp/4.png"))
116
116
  WebP.decode(filename, out_filename)
117
-
118
-
117
+
118
+
119
119
  Decode webp image to pam, ppm or pgm format of image:
120
120
 
121
121
  filename = File.expand_path(File.join(File.dirname(__FILE__), "spec/factories/4.webp"))
@@ -123,14 +123,14 @@ Decode webp image to pam, ppm or pgm format of image:
123
123
  WebP.decode(filename, out_filename, output_format: :pam)
124
124
  WebP.decode(filename, out_filename, output_format: :ppm)
125
125
  WebP.decode(filename, out_filename, output_format: :pgm)
126
-
127
-
126
+
127
+
128
128
  Decode webp image with options:
129
129
 
130
130
  WebP.encode(filename, out_filename, resize_w: 100, resize_h: 200)
131
131
  WebP.encode(filename, out_filename, crop_x: 0, cropt_y: 0, crop_w: 100, crop_h: 100)
132
-
133
-
132
+
133
+
134
134
  Possible decode options:
135
135
 
136
136
  * **bypass\_filtering** (bool) - disable in-loop filtering
@@ -57,6 +57,13 @@ int webp_encode(const char *in_file, const char *out_file, const FfiWebpEncodeCo
57
57
  int keep_alpha = 1;
58
58
  WebPPicture picture;
59
59
  WebPConfig config;
60
+
61
+ if (!WebPPictureInit(&picture) ||
62
+ !WebPConfigInit(&config)) {
63
+ //fprintf(stderr, "Error! Version mismatch!\n");
64
+ return 1;
65
+ }
66
+
60
67
  // OPTIONS BEGIN
61
68
  if (encode_config->lossless == 0 || encode_config->lossless == 1){
62
69
  config.lossless = encode_config->lossless;
@@ -120,25 +127,19 @@ int webp_encode(const char *in_file, const char *out_file, const FfiWebpEncodeCo
120
127
  picture.height = encode_config->height;
121
128
  }
122
129
  // OPTIONS END
123
-
124
- if (!WebPPictureInit(&picture) ||
125
- !WebPConfigInit(&config)) {
126
- //fprintf(stderr, "Error! Version mismatch!\n");
127
- return 1;
128
- }
129
-
130
+
130
131
  if (!WebPValidateConfig(&config)) {
131
132
  //fprintf(stderr, "Error! Invalid configuration.\n");
132
133
  return_value = 2;
133
134
  goto Error;
134
135
  }
135
-
136
+
136
137
  if (!UtilReadPicture(in_file, &picture, keep_alpha)) {
137
138
  //fprintf(stderr, "Error! Cannot read input picture file '%s'\n", in_file);
138
139
  return_value = 3;
139
140
  goto Error;
140
141
  }
141
-
142
+
142
143
  out = fopen(out_file, "wb");
143
144
  if (out == NULL) {
144
145
  //fprintf(stderr, "Error! Cannot open output file '%s'\n", out_file);
@@ -147,7 +148,7 @@ int webp_encode(const char *in_file, const char *out_file, const FfiWebpEncodeCo
147
148
  }
148
149
  picture.writer = EncodeWriter;
149
150
  picture.custom_ptr = (void*)out;
150
-
151
+
151
152
  if ((encode_config->crop_w | encode_config->crop_h) > 0){
152
153
  if (!WebPPictureView(&picture, encode_config->crop_x, encode_config->crop_y, encode_config->crop_w, encode_config->crop_h, &picture)) {
153
154
  //fprintf(stderr, "Error! Cannot crop picture\n");
@@ -155,7 +156,7 @@ int webp_encode(const char *in_file, const char *out_file, const FfiWebpEncodeCo
155
156
  goto Error;
156
157
  }
157
158
  }
158
-
159
+
159
160
  if ((encode_config->resize_w | encode_config->resize_h) > 0) {
160
161
  if (!WebPPictureRescale(&picture, encode_config->resize_w, encode_config->resize_h)) {
161
162
  //fprintf(stderr, "Error! Cannot resize picture\n");
@@ -163,18 +164,18 @@ int webp_encode(const char *in_file, const char *out_file, const FfiWebpEncodeCo
163
164
  goto Error;
164
165
  }
165
166
  }
166
-
167
+
167
168
  if (picture.extra_info_type > 0) {
168
169
  AllocExtraInfo(&picture);
169
170
  }
170
-
171
+
171
172
  if (!WebPEncode(&config, &picture)) {
172
173
  //fprintf(stderr, "Error! Cannot encode picture as WebP\n");
173
174
  return_value = 7;
174
175
  goto Error;
175
176
  }
176
177
  return_value = 0;
177
-
178
+
178
179
  Error:
179
180
  free(picture.extra_info);
180
181
  WebPPictureFree(&picture);
@@ -198,7 +199,7 @@ int webp_decode(const char *in_file, const char *out_file, const FfiWebpDecodeCo
198
199
  //fprintf(stderr, "Library version mismatch!\n");
199
200
  return 1;
200
201
  }
201
-
202
+
202
203
  if (decode_config->output_format != format){
203
204
  format = decode_config->output_format;
204
205
  }
@@ -223,20 +224,20 @@ int webp_decode(const char *in_file, const char *out_file, const FfiWebpDecodeCo
223
224
  config.options.scaled_width = decode_config->resize_w;
224
225
  config.options.scaled_height = decode_config->resize_h;
225
226
  }
226
-
227
+
227
228
  VP8StatusCode status = VP8_STATUS_OK;
228
229
  size_t data_size = 0;
229
230
  const uint8_t* data = NULL;
230
-
231
+
231
232
  if (!UtilReadFile(in_file, &data, &data_size)) return -1;
232
-
233
+
233
234
  status = WebPGetFeatures(data, data_size, bitstream);
234
235
  if (status != VP8_STATUS_OK) {
235
236
  //fprintf(stderr, "This is invalid webp image!\n");
236
237
  return_value = 2;
237
238
  goto Error;
238
239
  }
239
-
240
+
240
241
  switch (format) {
241
242
  case PNG:
242
243
  output_buffer->colorspace = bitstream->has_alpha ? MODE_RGBA : MODE_RGB;
@@ -258,7 +259,7 @@ int webp_decode(const char *in_file, const char *out_file, const FfiWebpDecodeCo
258
259
  return 3;
259
260
  }
260
261
  status = WebPDecode(data, data_size, &config);
261
-
262
+
262
263
  if (status != VP8_STATUS_OK) {
263
264
  //fprintf(stderr, "Decoding of %s failed.\n", in_file);
264
265
  return_value = 4;
@@ -266,8 +267,8 @@ int webp_decode(const char *in_file, const char *out_file, const FfiWebpDecodeCo
266
267
  }
267
268
  UtilSaveOutput(output_buffer, format, out_file);
268
269
  return_value = 0;
269
-
270
- Error:
270
+
271
+ Error:
271
272
  free((void*)data);
272
273
  WebPFreeDecBuffer(output_buffer);
273
274
  return return_value;
data/lib/webp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module WebP
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -3,5 +3,7 @@ require 'rspec'
3
3
  require File.dirname(__FILE__) + "/../lib/webp_ffi"
4
4
 
5
5
  RSpec.configure do |config|
6
-
6
+ config.expect_with :rspec do |c|
7
+ c.syntax = :expect
8
+ end
7
9
  end
@@ -29,7 +29,7 @@ describe WebP do
29
29
  }
30
30
  }
31
31
  }
32
-
32
+
33
33
  before :all do
34
34
  @out_dir = File.expand_path(File.join(File.dirname(__FILE__), "../tmp/"))
35
35
  Dir.mkdir(@out_dir) unless File.exists?(@out_dir)
@@ -42,29 +42,29 @@ describe WebP do
42
42
  end
43
43
 
44
44
  it "calculate plus 100 by test_c (verify C)" do
45
- WebP::C.test_c(100).should == 200
46
- WebP::C.test_c(150).should == 250
45
+ expect(WebP::C.test_c(100)).to eq(200)
46
+ expect(WebP::C.test_c(150)).to eq(250)
47
47
  end
48
-
48
+
49
49
  it "decoder version" do
50
- WebP.decoder_version.should_not be_nil
51
- WebP.decoder_version.should =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)$/
50
+ expect(WebP.decoder_version).not_to be_nil
51
+ expect(WebP.decoder_version).to match(/^([0-9]+)\.([0-9]+)\.([0-9]+)$/)
52
52
  end
53
-
53
+
54
54
  it "encoder version" do
55
- WebP.encoder_version.should_not be_nil
56
- WebP.decoder_version.should =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)$/
55
+ expect(WebP.encoder_version).not_to be_nil
56
+ expect(WebP.decoder_version).to match(/^([0-9]+)\.([0-9]+)\.([0-9]+)$/)
57
57
  end
58
-
58
+
59
59
  context "webp_size" do
60
60
  factories[:webp].each do |image|
61
61
  it "#{image} image size == #{factories[:info][image][:size]}" do
62
62
  filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.webp"))
63
63
  data = File.open(filename, "rb").read
64
64
  info = WebP.webp_size(data)
65
- info.class.should == Array
66
- info.size.should == 2
67
- info.should == factories[:info][image][:size]
65
+ expect(info.class).to eq(Array)
66
+ expect(info.size).to eq(2)
67
+ expect(info).to eq(factories[:info][image][:size])
68
68
  end
69
69
  end
70
70
  it "raise InvalidImageFormatError for non-webp image" do
@@ -73,27 +73,27 @@ describe WebP do
73
73
  expect { WebP.webp_size(data) }.to raise_error WebP::InvalidImageFormatError
74
74
  end
75
75
  end
76
-
76
+
77
77
  context "encode" do
78
78
  factories[:png].each do |image|
79
79
  it "#{image}.png image" do
80
80
  in_filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.png"))
81
81
  out_filename = File.expand_path(File.join(@out_dir, "#{image}.png.webp"))
82
- WebP.encode(in_filename, out_filename).should be_true
82
+ expect(WebP.encode(in_filename, out_filename)).to be_true
83
83
  end
84
84
  end
85
85
  factories[:jpg].each do |image|
86
86
  it "#{image}.jpg image" do
87
87
  in_filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.jpg"))
88
88
  out_filename = File.expand_path(File.join(@out_dir, "#{image}.jpg.webp"))
89
- WebP.encode(in_filename, out_filename).should be_true
89
+ expect(WebP.encode(in_filename, out_filename)).to be_true
90
90
  end
91
91
  end
92
92
  factories[:tiff].each do |image|
93
93
  it "#{image}.tif image" do
94
94
  in_filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.tif"))
95
95
  out_filename = File.expand_path(File.join(@out_dir, "#{image}.tif.webp"))
96
- WebP.encode(in_filename, out_filename).should be_true
96
+ expect(WebP.encode(in_filename, out_filename)).to be_true
97
97
  end
98
98
  end
99
99
  factories[:webp].each do |image|
@@ -122,13 +122,13 @@ describe WebP do
122
122
  end
123
123
  end
124
124
  end
125
-
125
+
126
126
  context "decode" do
127
127
  factories[:webp].each do |image|
128
128
  it "#{image}.webp image" do
129
129
  in_filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.webp"))
130
130
  out_filename = File.expand_path(File.join(@out_dir, "#{image}.webp.png"))
131
- WebP.decode(in_filename, out_filename).should be_true
131
+ expect(WebP.decode(in_filename, out_filename)).to be_true
132
132
  end
133
133
  end
134
134
  context "with output_format" do
@@ -137,7 +137,7 @@ describe WebP do
137
137
  it "#{image}.webp image to #{output_format}" do
138
138
  in_filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.webp"))
139
139
  out_filename = File.expand_path(File.join(@out_dir, "#{image}.#{output_format}.png"))
140
- WebP.decode(in_filename, out_filename, output_format: output_format).should be_true
140
+ expect(WebP.decode(in_filename, out_filename, output_format: output_format)).to be_true
141
141
  end
142
142
  end
143
143
  end
@@ -147,12 +147,12 @@ describe WebP do
147
147
  it "#{image}.webp image to png and crop" do
148
148
  in_filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.webp"))
149
149
  out_filename = File.expand_path(File.join(@out_dir, "#{image}_crop.png"))
150
- WebP.decode(in_filename, out_filename, crop_w: 200, crop_h: 200).should be_true
150
+ expect(WebP.decode(in_filename, out_filename, crop_w: 200, crop_h: 200)).to be_true
151
151
  end
152
152
  it "#{image}.webp image to png and scale" do
153
153
  in_filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.webp"))
154
154
  out_filename = File.expand_path(File.join(@out_dir, "#{image}_resize.png"))
155
- WebP.decode(in_filename, out_filename, resize_w: 200, resize_h: 200).should be_true
155
+ expect(WebP.decode(in_filename, out_filename, resize_w: 200, resize_h: 200)).to be_true
156
156
  end
157
157
  end
158
158
  end
data/webp-ffi.gemspec CHANGED
@@ -19,10 +19,10 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
  spec.extensions << 'ext/webp_ffi/Rakefile'
21
21
 
22
- spec.add_runtime_dependency "ffi", "~> 1.9.0"
23
- spec.add_runtime_dependency "ffi-compiler", "~> 0.1.2"
22
+ spec.add_runtime_dependency "ffi", ">= 1.9.0"
23
+ spec.add_runtime_dependency "ffi-compiler", ">= 0.1.2"
24
24
 
25
25
  spec.add_development_dependency "bundler", ">= 1.2"
26
26
  spec.add_development_dependency "rake"
27
- spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "rspec", ">= 2.14.0"
28
28
  end
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webp-ffi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Vasyliev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-17 00:00:00.000000000 Z
11
+ date: 2013-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.9.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.9.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: ffi-compiler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.1.2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.1.2
41
41
  - !ruby/object:Gem::Dependency
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - '>='
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 2.14.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - '>='
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 2.14.0
83
83
  description: Ruby wrapper for libwebp
84
84
  email:
85
85
  - leopard.not.a@gmail.com