webp-ffi 0.2.4 → 0.3.1

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
- SHA1:
3
- metadata.gz: 34b1495b74a5385dd27950b6e4bc2f4e5391fa97
4
- data.tar.gz: 90b299d673ff0c22afef51ffbb61d6fabd4733ae
2
+ SHA256:
3
+ metadata.gz: 9dbe6d1f0ae67d2687cd1a8d9529c895a7459911b3fd2d4ad4d16b35505263e5
4
+ data.tar.gz: 1b933a2313048dcfa7d4e89cbe230d0fe18edae1d07f2f25672a82f53b4fb01b
5
5
  SHA512:
6
- metadata.gz: fe4fd8a5a8b3fe9b741bc028c55f13272ff1e642961d88b9bc4bbcbf74b4554c0312617a0e13b3b106473846587d0d4cbee2a0ae0818347e0f471d91badee2f1
7
- data.tar.gz: 7a7b54b518cee8bb959c6a074c4983991492ec1cce5192a8f915568d748f20ad7570581952dd5c1b09ce0e471d87104532ff42c6cb849413a05f6e6b0f89eba4
6
+ metadata.gz: d1548837a12b307bccd667ae8a10abcf711a84c60cea15be6a5b98f2580666c73de9195fd9b32b877d9ba9df377d4a75f8457d7015c8f77c1ba8f84e032861a0
7
+ data.tar.gz: 46bae931c7e2aa2e61adf94cdc252ae703fd0e7a0333f6a14b83cbbfb4b3dc689b65934ac28a58cd5fb2ffae0b1cfe9a5d3d5822b54b9525a981328eee306a34
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.1.2
1
+ 2.7.1
data/.travis.yml CHANGED
@@ -1,23 +1,38 @@
1
1
  language: ruby
2
+
2
3
  before_install:
3
4
  - ./spec/travis_build.sh > /dev/null 2>&1
5
+ - export LD_FLAGS=-L$HOME/opt/lib
6
+ - export LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib:$HOME/opt/lib
7
+ - export CPATH=$CPATH:$HOME/opt/include
8
+
4
9
  rvm:
5
- - 1.9.2
6
- - 1.9.3
7
- - 2.0.0
8
- - 2.1.2
10
+ - 2.5
11
+ - 2.6
12
+ - 2.7
13
+ - 3.0
9
14
  - jruby-19mode
10
15
  - rbx-19mode
11
16
  - ruby-head
12
17
  - jruby-head
18
+ env:
19
+ - LIBWEBP_VERSION=0.4.4
20
+ - LIBWEBP_VERSION=1.0.2
21
+
22
+ cache: bundler
23
+ sudo: false
24
+ dist: xenial
25
+
13
26
  notifications:
14
27
  email: false
28
+
15
29
  branches:
16
30
  only:
17
31
  - master
18
32
  - development
33
+
19
34
  matrix:
20
35
  allow_failures:
21
36
  - rvm: rbx-19mode
22
37
  - rvm: ruby-head
23
- - rvm: jruby-head
38
+ - rvm: jruby-head
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## v0.2.7
2
+
3
+ * Fix build for old libwebp versions
4
+
5
+ ## v0.2.6
6
+
7
+ * Tested on webp 1.0.2
8
+ * Added near_lossless option
9
+
10
+ ## v0.2.5
11
+
12
+ * Fix build for Travis CI docker containers
13
+
1
14
  ## v0.2.4
2
15
 
3
16
  * DRY C code and split into files each read/write formats
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Webp-ffi
2
2
 
3
- [![Build Status](https://travis-ci.org/le0pard/webp-ffi.png)](https://travis-ci.org/le0pard/webp-ffi)
4
- [![Code Climate](https://codeclimate.com/github/le0pard/webp-ffi.png)](https://codeclimate.com/github/le0pard/webp-ffi)
3
+ [![Build Status](https://travis-ci.com/le0pard/webp-ffi.svg?branch=master)](https://travis-ci.com/le0pard/webp-ffi)
4
+ [![Code Climate](https://codeclimate.com/github/le0pard/webp-ffi/badges/gpa.svg)](https://codeclimate.com/github/le0pard/webp-ffi)
5
5
 
6
6
  Ruby wrapper for libwebp. What is WebP?
7
7
 
@@ -17,7 +17,11 @@ First of all you should have install libraries: libpng, libjpeg and libtiff.
17
17
 
18
18
  For Ubuntu, Debian:
19
19
 
20
- sudo apt-get install libjpeg-dev libpng-dev libtiff-dev
20
+ sudo apt-get install libjpeg-dev libpng-dev libtiff-dev libwebp-dev
21
+
22
+ For Fedora, CentOS:
23
+
24
+ sudo dnf install libjpeg-devel libpng-devel libtiff-devel libwebp-devel
21
25
 
22
26
  For Mac OS:
23
27
 
@@ -27,7 +31,7 @@ or (for MacPorts):
27
31
 
28
32
  sudo port install jpeg libpng tiff
29
33
 
30
- Next, you should [install libwebp](https://developers.google.com/speed/webp/docs/compiling) (if you didn't install it by `brew` in Mac OS). This gem is not support Windows systems (sorry).
34
+ Next, you should [install libwebp](https://developers.google.com/speed/webp/docs/compiling) (if you didn't install it by `brew` in Mac OS or by `apt-get` in Ubuntu or Debian). Webp library version should be >= 0.3.0. This gem is not support Windows systems.
31
35
 
32
36
  ### Final part
33
37
 
@@ -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/Rakefile CHANGED
@@ -20,8 +20,8 @@ namespace "ffi-compiler" do
20
20
  c.have_library?('png')
21
21
  c.have_library?('jpeg')
22
22
  c.have_library?('tiff')
23
- c.cflags << "-arch x86_64" if c.platform.mac?
24
- c.ldflags << "-arch x86_64" if c.platform.mac?
23
+ c.ldflags << ENV['LD_FLAGS'] if ENV['LD_FLAGS']
24
+ c.cflags << ENV['C_FLAGS'] if ENV['C_FLAGS']
25
25
  end
26
26
  end
27
27
  task :compile => ["ffi-compiler:default"]
@@ -35,4 +35,4 @@ task :default => [:clean, :compile, :spec]
35
35
 
36
36
  CLEAN.include('ext/**/*{.o,.log,.so,.bundle}')
37
37
  CLEAN.include('lib/**/*{.o,.log,.so,.bundle}')
38
- CLEAN.include('ext/**/Makefile')
38
+ CLEAN.include('ext/**/Makefile')
@@ -14,7 +14,6 @@ FFI::Compiler::CompileTask.new('webp_ffi') do |c|
14
14
  c.have_library?('png')
15
15
  c.have_library?('jpeg')
16
16
  c.have_library?('tiff')
17
- # compiler flags
18
- c.cflags << "-arch x86_64" if c.platform.mac?
19
- c.ldflags << "-arch x86_64" if c.platform.mac?
17
+ c.ldflags << ENV['LD_FLAGS'] if ENV['LD_FLAGS']
18
+ c.cflags << ENV['C_FLAGS'] if ENV['C_FLAGS']
20
19
  end
@@ -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
@@ -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
@@ -12,6 +12,7 @@ module WebP
12
12
  # struct
13
13
  class FfiWebpEncodeConfig < FFI::Struct
14
14
  layout :lossless, :int,
15
+ :near_lossless, :int,
15
16
  :quality, :float,
16
17
  :method, :int,
17
18
  :target_size, :int,
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
@@ -1,3 +1,3 @@
1
1
  module WebP
2
- VERSION = "0.2.4"
2
+ VERSION = "0.3.1"
3
3
  end
data/spec/travis_build.sh CHANGED
@@ -1,8 +1,6 @@
1
1
  #/usr/bin/env sh
2
- wget http://webp.googlecode.com/files/libwebp-0.4.0.tar.gz
3
- tar xvzf libwebp-0.4.0.tar.gz
4
- cd libwebp-0.4.0
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
@@ -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
4
+ version: 0.3.1
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: 2014-07-05 00:00:00.000000000 Z
11
+ date: 2021-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -133,7 +133,7 @@ homepage: http://leopard.in.ua/webp-ffi
133
133
  licenses:
134
134
  - MIT
135
135
  metadata: {}
136
- post_install_message:
136
+ post_install_message:
137
137
  rdoc_options: []
138
138
  require_paths:
139
139
  - lib
@@ -148,9 +148,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
148
  - !ruby/object:Gem::Version
149
149
  version: '0'
150
150
  requirements: []
151
- rubyforge_project:
152
- rubygems_version: 2.2.2
153
- signing_key:
151
+ rubygems_version: 3.1.2
152
+ signing_key:
154
153
  specification_version: 4
155
154
  summary: Ruby wrapper for libwebp
156
155
  test_files: