webp-ffi 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.ruby-version +1 -1
- data/.travis.yml +20 -5
- data/CHANGELOG.md +17 -0
- data/README.md +50 -4
- data/Rakefile +3 -3
- data/ext/webp_ffi/Rakefile +6 -2
- data/ext/webp_ffi/jpegdec.c +80 -0
- data/ext/webp_ffi/jpegdec.h +17 -0
- data/ext/webp_ffi/pngdec.c +212 -0
- data/ext/webp_ffi/pngdec.h +24 -0
- data/ext/webp_ffi/tiffdec.c +197 -0
- data/ext/webp_ffi/tiffdec.h +23 -0
- data/ext/webp_ffi/util.c +4 -470
- data/ext/webp_ffi/webp_ffi.c +9 -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 +5 -7
- data/spec/webp_ffi_spec.rb +20 -8
- data/webp-ffi.gemspec +1 -1
- metadata +14 -9
data/ext/webp_ffi/webp_ffi.c
CHANGED
@@ -64,6 +64,14 @@ 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
|
+
|
68
|
+
#if (ENC_MAJ_VERSION == 0 && ENC_MIN_VERSION > 4) || ENC_MAJ_VERSION > 0
|
69
|
+
if (encode_config->near_lossless >= 0 && encode_config->near_lossless <= 100){
|
70
|
+
config.near_lossless = encode_config->near_lossless;
|
71
|
+
config.lossless = 1; // use near-lossless only with lossless
|
72
|
+
}
|
73
|
+
#endif
|
74
|
+
|
67
75
|
if (encode_config->quality >= 0 && encode_config->quality <= 100){
|
68
76
|
config.quality = encode_config->quality;
|
69
77
|
}
|
@@ -288,4 +296,4 @@ int test_c(int n) {
|
|
288
296
|
|
289
297
|
#if defined(__cplusplus) || defined(c_plusplus)
|
290
298
|
} // extern "C"
|
291
|
-
#endif
|
299
|
+
#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,8 +1,6 @@
|
|
1
1
|
#/usr/bin/env sh
|
2
|
-
wget http://
|
3
|
-
tar xvzf libwebp
|
4
|
-
cd libwebp
|
5
|
-
./configure
|
6
|
-
make
|
7
|
-
sudo make install
|
8
|
-
sudo ln -fs /usr/local/lib/libwebp.* /usr/lib/
|
2
|
+
wget http://downloads.webmproject.org/releases/webp/libwebp-$LIBWEBP_VERSION.tar.gz
|
3
|
+
tar xvzf libwebp-$LIBWEBP_VERSION.tar.gz
|
4
|
+
cd libwebp-$LIBWEBP_VERSION
|
5
|
+
./configure --prefix=$HOME/opt
|
6
|
+
make && make install
|
data/spec/webp_ffi_spec.rb
CHANGED
@@ -79,21 +79,33 @@ describe WebP do
|
|
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
|
-
expect(WebP.encode(in_filename, out_filename)).to
|
82
|
+
expect(WebP.encode(in_filename, out_filename)).to be_truthy
|
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
|
83
89
|
end
|
84
90
|
end
|
85
91
|
factories[:jpg].each do |image|
|
86
92
|
it "#{image}.jpg image" do
|
87
93
|
in_filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.jpg"))
|
88
94
|
out_filename = File.expand_path(File.join(@out_dir, "#{image}.jpg.webp"))
|
89
|
-
expect(WebP.encode(in_filename, out_filename)).to
|
95
|
+
expect(WebP.encode(in_filename, out_filename)).to be_truthy
|
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
|
90
102
|
end
|
91
103
|
end
|
92
104
|
factories[:tiff].each do |image|
|
93
105
|
it "#{image}.tif image" do
|
94
106
|
in_filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.tif"))
|
95
107
|
out_filename = File.expand_path(File.join(@out_dir, "#{image}.tif.webp"))
|
96
|
-
expect(WebP.encode(in_filename, out_filename)).to
|
108
|
+
expect(WebP.encode(in_filename, out_filename)).to be_truthy
|
97
109
|
end
|
98
110
|
end
|
99
111
|
factories[:webp].each do |image|
|
@@ -128,7 +140,7 @@ describe WebP do
|
|
128
140
|
it "#{image}.webp image" do
|
129
141
|
in_filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.webp"))
|
130
142
|
out_filename = File.expand_path(File.join(@out_dir, "#{image}.webp.png"))
|
131
|
-
expect(WebP.decode(in_filename, out_filename)).to
|
143
|
+
expect(WebP.decode(in_filename, out_filename)).to be_truthy
|
132
144
|
end
|
133
145
|
end
|
134
146
|
context "with output_format" do
|
@@ -137,7 +149,7 @@ describe WebP do
|
|
137
149
|
it "#{image}.webp image to #{output_format}" do
|
138
150
|
in_filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.webp"))
|
139
151
|
out_filename = File.expand_path(File.join(@out_dir, "#{image}.#{output_format}.png"))
|
140
|
-
expect(WebP.decode(in_filename, out_filename, output_format: output_format)).to
|
152
|
+
expect(WebP.decode(in_filename, out_filename, output_format: output_format)).to be_truthy
|
141
153
|
end
|
142
154
|
end
|
143
155
|
end
|
@@ -147,12 +159,12 @@ describe WebP do
|
|
147
159
|
it "#{image}.webp image to png and crop" do
|
148
160
|
in_filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.webp"))
|
149
161
|
out_filename = File.expand_path(File.join(@out_dir, "#{image}_crop.png"))
|
150
|
-
expect(WebP.decode(in_filename, out_filename, crop_w: 200, crop_h: 200)).to
|
162
|
+
expect(WebP.decode(in_filename, out_filename, crop_w: 200, crop_h: 200)).to be_truthy
|
151
163
|
end
|
152
164
|
it "#{image}.webp image to png and scale" do
|
153
165
|
in_filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.webp"))
|
154
166
|
out_filename = File.expand_path(File.join(@out_dir, "#{image}_resize.png"))
|
155
|
-
expect(WebP.decode(in_filename, out_filename, resize_w: 200, resize_h: 200)).to
|
167
|
+
expect(WebP.decode(in_filename, out_filename, resize_w: 200, resize_h: 200)).to be_truthy
|
156
168
|
end
|
157
169
|
end
|
158
170
|
end
|
@@ -176,4 +188,4 @@ describe WebP do
|
|
176
188
|
end
|
177
189
|
end
|
178
190
|
|
179
|
-
end
|
191
|
+
end
|
data/webp-ffi.gemspec
CHANGED
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey Vasyliev
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: '3'
|
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:
|
82
|
+
version: '3'
|
83
83
|
description: Ruby wrapper for libwebp
|
84
84
|
email:
|
85
85
|
- leopard.not.a@gmail.com
|
@@ -97,6 +97,12 @@ files:
|
|
97
97
|
- README.md
|
98
98
|
- Rakefile
|
99
99
|
- ext/webp_ffi/Rakefile
|
100
|
+
- ext/webp_ffi/jpegdec.c
|
101
|
+
- ext/webp_ffi/jpegdec.h
|
102
|
+
- ext/webp_ffi/pngdec.c
|
103
|
+
- ext/webp_ffi/pngdec.h
|
104
|
+
- ext/webp_ffi/tiffdec.c
|
105
|
+
- ext/webp_ffi/tiffdec.h
|
100
106
|
- ext/webp_ffi/util.c
|
101
107
|
- ext/webp_ffi/util.h
|
102
108
|
- ext/webp_ffi/webp_ffi.c
|
@@ -127,7 +133,7 @@ homepage: http://leopard.in.ua/webp-ffi
|
|
127
133
|
licenses:
|
128
134
|
- MIT
|
129
135
|
metadata: {}
|
130
|
-
post_install_message:
|
136
|
+
post_install_message:
|
131
137
|
rdoc_options: []
|
132
138
|
require_paths:
|
133
139
|
- lib
|
@@ -142,9 +148,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
148
|
- !ruby/object:Gem::Version
|
143
149
|
version: '0'
|
144
150
|
requirements: []
|
145
|
-
|
146
|
-
|
147
|
-
signing_key:
|
151
|
+
rubygems_version: 3.1.2
|
152
|
+
signing_key:
|
148
153
|
specification_version: 4
|
149
154
|
summary: Ruby wrapper for libwebp
|
150
155
|
test_files:
|