webp-ffi 0.2.5 → 0.2.6
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.
- checksums.yaml +5 -5
- data/.ruby-version +1 -1
- data/.travis.yml +7 -3
- data/CHANGELOG.md +9 -0
- data/README.md +46 -0
- data/ext/webp_ffi/webp_ffi.c +5 -1
- data/ext/webp_ffi/webp_ffi.h +4 -3
- data/lib/webp/c.rb +1 -0
- data/lib/webp/options.rb +1 -1
- data/lib/webp/version.rb +1 -1
- data/spec/travis_build.sh +3 -3
- data/spec/webp_ffi_spec.rb +13 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 976dae5457f3f3f651095f92ac882a9dc9f8dbe5bb52a99cf07d834c2ef020b3
|
4
|
+
data.tar.gz: 914c57979aa313a2f999b9031cecd60439fa6a73d4e4e81c0b8c61263c3d1539
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bfeb83ba2b884165cabba2dba3409eb6ea1c6f9def8190f2a5f3ac86c2393b91faa432ae1258b36410a02921b2a1273d5bd4e50c04ca5b0e4e6c19f6a5b9e8a
|
7
|
+
data.tar.gz: fd9fc4f3ded81c06a54c9c606fa63c6d51ef7c1943be9a59ade65124d5589ed4216e20d823a74fcc80a65be09c61a9f99955b2cbd3817a5e7d52d732df1e7879
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.5.3
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -19,6 +19,10 @@ For Ubuntu, Debian:
|
|
19
19
|
|
20
20
|
sudo apt-get install libjpeg-dev libpng-dev libtiff-dev libwebp-dev
|
21
21
|
|
22
|
+
For Fedora, CentOS:
|
23
|
+
|
24
|
+
sudo dnf install libjpeg-devel libpng-devel libtiff-devel libwebp-devel
|
25
|
+
|
22
26
|
For Mac OS:
|
23
27
|
|
24
28
|
brew install libjpg libpng libtiff webp
|
@@ -85,6 +89,7 @@ Encode png, jpg or tiff image to webp with options:
|
|
85
89
|
Possible encode options:
|
86
90
|
|
87
91
|
* **lossless** (int) - Lossless encoding (0=lossy(default), 1=lossless)
|
92
|
+
* **near_lossless** (int) - Use near-lossless image preprocessing (0=maximum preprocessing, 100=no preprocessing(default))
|
88
93
|
* **quality** (float) - between 0 (smallest file) and 100 (biggest)
|
89
94
|
* **method** (int) - quality/speed trade-off (0=fast, 6=slower-better)
|
90
95
|
* **target\_size** (int) - if non-zero, set the desired target size in bytes. Takes precedence over the 'compression' parameter
|
@@ -142,6 +147,47 @@ Possible decode options:
|
|
142
147
|
* **crop\_x** (int), **crop\_y** (int), **crop\_w** (int), **crop\_h** (int) - crop picture with the given rectangle
|
143
148
|
* **resize\_w** (int), **resize\_h** (int) - resize picture (after any cropping)
|
144
149
|
|
150
|
+
## Rails assets pipeline integration
|
151
|
+
|
152
|
+
For integration with Rails 3+ you can use very simple rake task:
|
153
|
+
|
154
|
+
```ruby
|
155
|
+
# Place this code in lib/tasks/assets.rake
|
156
|
+
require 'webp-ffi'
|
157
|
+
|
158
|
+
namespace :assets do
|
159
|
+
desc "Create .webp versions of assets"
|
160
|
+
task :webp => :environment do
|
161
|
+
image_types = /\.(?:png|jpe?g)$/
|
162
|
+
|
163
|
+
public_assets = File.join(
|
164
|
+
Rails.root,
|
165
|
+
"public",
|
166
|
+
Rails.application.config.assets.prefix)
|
167
|
+
|
168
|
+
Dir["#{public_assets}/**/*"].each do |filename|
|
169
|
+
next unless filename =~ image_types
|
170
|
+
|
171
|
+
mtime = File.mtime(filename)
|
172
|
+
webp_file = "#{filename}.webp"
|
173
|
+
next if File.exist?(webp_file) && File.mtime(webp_file) >= mtime
|
174
|
+
begin
|
175
|
+
WebP.encode(filename, webp_file)
|
176
|
+
File.utime(mtime, mtime, webp_file)
|
177
|
+
puts "Webp converted image #{webp_file}"
|
178
|
+
rescue => e
|
179
|
+
puts "Webp convertion error of image #{webp_file}. Error info: #{e.message}"
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
# Hook into existing assets:precompile task
|
185
|
+
Rake::Task["assets:precompile"].enhance do
|
186
|
+
Rake::Task["assets:webp"].invoke
|
187
|
+
end
|
188
|
+
end
|
189
|
+
```
|
190
|
+
|
145
191
|
## Contributing
|
146
192
|
|
147
193
|
1. Fork it
|
data/ext/webp_ffi/webp_ffi.c
CHANGED
@@ -64,6 +64,10 @@ int webp_encode(const char *in_file, const char *out_file, const FfiWebpEncodeCo
|
|
64
64
|
if (encode_config->lossless == 0 || encode_config->lossless == 1){
|
65
65
|
config.lossless = encode_config->lossless;
|
66
66
|
}
|
67
|
+
if (encode_config->near_lossless >= 0 && encode_config->near_lossless <= 100){
|
68
|
+
config.near_lossless = encode_config->near_lossless;
|
69
|
+
config.lossless = 1; // use near-lossless only with lossless
|
70
|
+
}
|
67
71
|
if (encode_config->quality >= 0 && encode_config->quality <= 100){
|
68
72
|
config.quality = encode_config->quality;
|
69
73
|
}
|
@@ -288,4 +292,4 @@ int test_c(int n) {
|
|
288
292
|
|
289
293
|
#if defined(__cplusplus) || defined(c_plusplus)
|
290
294
|
} // extern "C"
|
291
|
-
#endif
|
295
|
+
#endif
|
data/ext/webp_ffi/webp_ffi.h
CHANGED
@@ -7,6 +7,7 @@ extern "C" {
|
|
7
7
|
|
8
8
|
typedef struct {
|
9
9
|
int lossless; // Lossless encoding (0=lossy(default), 1=lossless).
|
10
|
+
int near_lossless; // use near-lossless image preprocessing (0..100=off)
|
10
11
|
float quality; // between 0 (smallest file) and 100 (biggest)
|
11
12
|
int method; // quality/speed trade-off (0=fast, 6=slower-better)
|
12
13
|
|
@@ -42,7 +43,7 @@ extern "C" {
|
|
42
43
|
int crop_x, crop_y, crop_w, crop_h;
|
43
44
|
int resize_w, resize_h;
|
44
45
|
} FfiWebpEncodeConfig;
|
45
|
-
|
46
|
+
|
46
47
|
typedef struct {
|
47
48
|
OutputFileFormat output_format;
|
48
49
|
int bypass_filtering; // if true, skip the in-loop filtering
|
@@ -51,7 +52,7 @@ extern "C" {
|
|
51
52
|
int resize_w, resize_h;
|
52
53
|
int use_threads; // if true, use multi-threaded decoding
|
53
54
|
} FfiWebpDecodeConfig;
|
54
|
-
|
55
|
+
|
55
56
|
|
56
57
|
void decoder_version(char *version);
|
57
58
|
void encoder_version(char *version);
|
@@ -64,4 +65,4 @@ extern "C" {
|
|
64
65
|
} // extern "C"
|
65
66
|
#endif
|
66
67
|
|
67
|
-
#endif /* _WEBP_FFI_H_ */
|
68
|
+
#endif /* _WEBP_FFI_H_ */
|
data/lib/webp/c.rb
CHANGED
data/lib/webp/options.rb
CHANGED
@@ -8,7 +8,7 @@ module WebP
|
|
8
8
|
def encode_pointer
|
9
9
|
options_pointer = FFI::MemoryPointer.new :char, C::FfiWebpEncodeConfig.size, false
|
10
10
|
options_struct = C::FfiWebpEncodeConfig.new options_pointer
|
11
|
-
[:lossless, :method, :target_size, :target_PSNR, :segments,
|
11
|
+
[:lossless, :near_lossless, :method, :target_size, :target_PSNR, :segments,
|
12
12
|
:sns_strength, :filter_strength, :filter_sharpness,
|
13
13
|
:filter_type, :autofilter, :alpha_compression, :alpha_filtering,
|
14
14
|
:alpha_quality, :pass, :show_compressed, :preprocessing, :partitions,
|
data/lib/webp/version.rb
CHANGED
data/spec/travis_build.sh
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#/usr/bin/env sh
|
2
|
-
wget http://downloads.webmproject.org/releases/webp/libwebp-0.
|
3
|
-
tar xvzf libwebp-0.
|
4
|
-
cd libwebp-0.
|
2
|
+
wget http://downloads.webmproject.org/releases/webp/libwebp-1.0.2.tar.gz
|
3
|
+
tar xvzf libwebp-1.0.2.tar.gz
|
4
|
+
cd libwebp-1.0.2
|
5
5
|
./configure --prefix=$HOME/opt
|
6
6
|
make && make install
|
data/spec/webp_ffi_spec.rb
CHANGED
@@ -81,6 +81,12 @@ describe WebP do
|
|
81
81
|
out_filename = File.expand_path(File.join(@out_dir, "#{image}.png.webp"))
|
82
82
|
expect(WebP.encode(in_filename, out_filename)).to be_truthy
|
83
83
|
end
|
84
|
+
|
85
|
+
it "#{image}.png image with near_lossless" do
|
86
|
+
in_filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.png"))
|
87
|
+
out_filename = File.expand_path(File.join(@out_dir, "#{image}_near_lossless.png.webp"))
|
88
|
+
expect(WebP.encode(in_filename, out_filename, near_lossless: 60)).to be_truthy
|
89
|
+
end
|
84
90
|
end
|
85
91
|
factories[:jpg].each do |image|
|
86
92
|
it "#{image}.jpg image" do
|
@@ -88,6 +94,12 @@ describe WebP do
|
|
88
94
|
out_filename = File.expand_path(File.join(@out_dir, "#{image}.jpg.webp"))
|
89
95
|
expect(WebP.encode(in_filename, out_filename)).to be_truthy
|
90
96
|
end
|
97
|
+
|
98
|
+
it "#{image}.jpg image with near_lossless" do
|
99
|
+
in_filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.jpg"))
|
100
|
+
out_filename = File.expand_path(File.join(@out_dir, "#{image}_near_lossless.jpg.webp"))
|
101
|
+
expect(WebP.encode(in_filename, out_filename, near_lossless: 60)).to be_truthy
|
102
|
+
end
|
91
103
|
end
|
92
104
|
factories[:tiff].each do |image|
|
93
105
|
it "#{image}.tif image" do
|
@@ -176,4 +188,4 @@ describe WebP do
|
|
176
188
|
end
|
177
189
|
end
|
178
190
|
|
179
|
-
end
|
191
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webp-ffi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey Vasyliev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -149,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
149
|
version: '0'
|
150
150
|
requirements: []
|
151
151
|
rubyforge_project:
|
152
|
-
rubygems_version: 2.
|
152
|
+
rubygems_version: 2.7.6
|
153
153
|
signing_key:
|
154
154
|
specification_version: 4
|
155
155
|
summary: Ruby wrapper for libwebp
|