webp-ffi 0.3.1 → 1.0.0
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 +4 -4
- data/CHANGELOG.md +65 -0
- data/LICENSE.txt +1 -1
- data/README.md +138 -27
- data/ext/webp_ffi/Rakefile +2 -18
- data/ext/webp_ffi/build_config.rb +119 -0
- data/ext/webp_ffi/jpegdec.c +104 -10
- data/ext/webp_ffi/jpegdec.h +5 -2
- data/ext/webp_ffi/metadata.c +138 -0
- data/ext/webp_ffi/metadata.h +49 -0
- data/ext/webp_ffi/pngdec.c +197 -20
- data/ext/webp_ffi/pngdec.h +7 -2
- data/ext/webp_ffi/tiffdec.c +187 -23
- data/ext/webp_ffi/tiffdec.h +12 -4
- data/ext/webp_ffi/util.c +82 -35
- data/ext/webp_ffi/util.h +28 -3
- data/ext/webp_ffi/webp_ffi.c +484 -165
- data/ext/webp_ffi/webp_ffi.h +47 -5
- data/lib/webp/c.rb +41 -7
- data/lib/webp/error.rb +65 -15
- data/lib/webp/info.rb +13 -0
- data/lib/webp/options.rb +129 -22
- data/lib/webp/version.rb +1 -1
- data/lib/webp/webp.rb +150 -32
- data/lib/webp_ffi.rb +1 -1
- data/sig/webp.rbs +74 -0
- metadata +31 -48
- data/.gitignore +0 -22
- data/.ruby-version +0 -1
- data/.travis.yml +0 -38
- data/Gemfile +0 -4
- data/Rakefile +0 -38
- data/lib/webp/libc.rb +0 -20
- data/spec/factories/1.png +0 -0
- data/spec/factories/1.webp +0 -0
- data/spec/factories/2.png +0 -0
- data/spec/factories/2.webp +0 -0
- data/spec/factories/3.jpg +0 -0
- data/spec/factories/3.webp +0 -0
- data/spec/factories/4.jpg +0 -0
- data/spec/factories/4.webp +0 -0
- data/spec/factories/5.tif +0 -0
- data/spec/factories/5.webp +0 -0
- data/spec/spec_helper.rb +0 -9
- data/spec/travis_build.sh +0 -6
- data/spec/webp_ffi_spec.rb +0 -191
- data/webp-ffi.gemspec +0 -28
data/sig/webp.rbs
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Type signatures for the public API of the webp-ffi gem.
|
|
2
|
+
module WebP
|
|
3
|
+
VERSION: String
|
|
4
|
+
|
|
5
|
+
# A file name: a String, a Pathname or anything with #to_path.
|
|
6
|
+
type path = String | _ToPath
|
|
7
|
+
|
|
8
|
+
# Image data: a String (or anything with #to_str) or an IO to read from.
|
|
9
|
+
type data = String | _ToStr | _ReadableData
|
|
10
|
+
|
|
11
|
+
interface _ReadableData
|
|
12
|
+
def read: () -> String?
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Options are a Hash with Symbol keys; see the README for the names.
|
|
16
|
+
type options = Hash[Symbol, untyped]
|
|
17
|
+
|
|
18
|
+
class Error < StandardError
|
|
19
|
+
attr_reader code: Integer?
|
|
20
|
+
attr_reader reason: Symbol?
|
|
21
|
+
|
|
22
|
+
def initialize: (?String? message, ?code: Integer?, ?reason: Symbol?) -> void
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
class InvalidImageFormatError < Error
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
class EncoderError < Error
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
class DecoderError < Error
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
class Info < Data
|
|
35
|
+
attr_reader width: Integer
|
|
36
|
+
attr_reader height: Integer
|
|
37
|
+
attr_reader format: :lossy | :lossless | :mixed
|
|
38
|
+
attr_reader alpha: bool
|
|
39
|
+
attr_reader animated: bool
|
|
40
|
+
attr_reader metadata: Array[:icc | :exif | :xmp]
|
|
41
|
+
|
|
42
|
+
def self.new: (width: Integer, height: Integer, format: :lossy | :lossless | :mixed, alpha: bool,
|
|
43
|
+
animated: bool, metadata: Array[:icc | :exif | :xmp]) -> instance
|
|
44
|
+
|
|
45
|
+
def lossless?: () -> bool
|
|
46
|
+
def alpha?: () -> bool
|
|
47
|
+
def animated?: () -> bool
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
class RGBAImage < Data
|
|
51
|
+
attr_reader rgba: String
|
|
52
|
+
attr_reader width: Integer
|
|
53
|
+
attr_reader height: Integer
|
|
54
|
+
|
|
55
|
+
def self.new: (rgba: String, width: Integer, height: Integer) -> instance
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def self.decoder_version: () -> String
|
|
59
|
+
def self.encoder_version: () -> String
|
|
60
|
+
|
|
61
|
+
def self.webp_size: (data data) -> [Integer, Integer]
|
|
62
|
+
| (nil) -> nil
|
|
63
|
+
def self.info: (data data) -> Info
|
|
64
|
+
| (nil) -> nil
|
|
65
|
+
|
|
66
|
+
def self.encode: (path input_file, path output_file, ?options options) -> true
|
|
67
|
+
def self.decode: (path input_file, path output_file, ?options options) -> true
|
|
68
|
+
|
|
69
|
+
def self.encode_data: (data data, ?options options) -> String
|
|
70
|
+
def self.decode_data: (data data, ?options options) -> String
|
|
71
|
+
|
|
72
|
+
def self.encode_rgba: (String | _ToStr | _ReadableData pixels, Integer width, Integer height, ?options options) -> String
|
|
73
|
+
def self.decode_rgba: (data data, ?options options) -> RGBAImage
|
|
74
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: webp-ffi
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
|
-
-
|
|
8
|
-
autorequire:
|
|
7
|
+
- Oleksii Vasyliev
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: ffi
|
|
@@ -38,6 +37,20 @@ dependencies:
|
|
|
38
37
|
- - ">="
|
|
39
38
|
- !ruby/object:Gem::Version
|
|
40
39
|
version: 0.1.2
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: rake
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
type: :runtime
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
41
54
|
- !ruby/object:Gem::Dependency
|
|
42
55
|
name: bundler
|
|
43
56
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -53,33 +66,33 @@ dependencies:
|
|
|
53
66
|
- !ruby/object:Gem::Version
|
|
54
67
|
version: '1.2'
|
|
55
68
|
- !ruby/object:Gem::Dependency
|
|
56
|
-
name:
|
|
69
|
+
name: rspec
|
|
57
70
|
requirement: !ruby/object:Gem::Requirement
|
|
58
71
|
requirements:
|
|
59
72
|
- - ">="
|
|
60
73
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '
|
|
74
|
+
version: '3'
|
|
62
75
|
type: :development
|
|
63
76
|
prerelease: false
|
|
64
77
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
78
|
requirements:
|
|
66
79
|
- - ">="
|
|
67
80
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: '
|
|
81
|
+
version: '3'
|
|
69
82
|
- !ruby/object:Gem::Dependency
|
|
70
|
-
name:
|
|
83
|
+
name: rbs
|
|
71
84
|
requirement: !ruby/object:Gem::Requirement
|
|
72
85
|
requirements:
|
|
73
86
|
- - ">="
|
|
74
87
|
- !ruby/object:Gem::Version
|
|
75
|
-
version: '
|
|
88
|
+
version: '0'
|
|
76
89
|
type: :development
|
|
77
90
|
prerelease: false
|
|
78
91
|
version_requirements: !ruby/object:Gem::Requirement
|
|
79
92
|
requirements:
|
|
80
93
|
- - ">="
|
|
81
94
|
- !ruby/object:Gem::Version
|
|
82
|
-
version: '
|
|
95
|
+
version: '0'
|
|
83
96
|
description: Ruby wrapper for libwebp
|
|
84
97
|
email:
|
|
85
98
|
- leopard.not.a@gmail.com
|
|
@@ -88,17 +101,15 @@ extensions:
|
|
|
88
101
|
- ext/webp_ffi/Rakefile
|
|
89
102
|
extra_rdoc_files: []
|
|
90
103
|
files:
|
|
91
|
-
- ".gitignore"
|
|
92
|
-
- ".ruby-version"
|
|
93
|
-
- ".travis.yml"
|
|
94
104
|
- CHANGELOG.md
|
|
95
|
-
- Gemfile
|
|
96
105
|
- LICENSE.txt
|
|
97
106
|
- README.md
|
|
98
|
-
- Rakefile
|
|
99
107
|
- ext/webp_ffi/Rakefile
|
|
108
|
+
- ext/webp_ffi/build_config.rb
|
|
100
109
|
- ext/webp_ffi/jpegdec.c
|
|
101
110
|
- ext/webp_ffi/jpegdec.h
|
|
111
|
+
- ext/webp_ffi/metadata.c
|
|
112
|
+
- ext/webp_ffi/metadata.h
|
|
102
113
|
- ext/webp_ffi/pngdec.c
|
|
103
114
|
- ext/webp_ffi/pngdec.h
|
|
104
115
|
- ext/webp_ffi/tiffdec.c
|
|
@@ -110,30 +121,16 @@ files:
|
|
|
110
121
|
- lib/webp-ffi.rb
|
|
111
122
|
- lib/webp/c.rb
|
|
112
123
|
- lib/webp/error.rb
|
|
113
|
-
- lib/webp/
|
|
124
|
+
- lib/webp/info.rb
|
|
114
125
|
- lib/webp/options.rb
|
|
115
126
|
- lib/webp/version.rb
|
|
116
127
|
- lib/webp/webp.rb
|
|
117
128
|
- lib/webp_ffi.rb
|
|
118
|
-
-
|
|
119
|
-
- spec/factories/1.webp
|
|
120
|
-
- spec/factories/2.png
|
|
121
|
-
- spec/factories/2.webp
|
|
122
|
-
- spec/factories/3.jpg
|
|
123
|
-
- spec/factories/3.webp
|
|
124
|
-
- spec/factories/4.jpg
|
|
125
|
-
- spec/factories/4.webp
|
|
126
|
-
- spec/factories/5.tif
|
|
127
|
-
- spec/factories/5.webp
|
|
128
|
-
- spec/spec_helper.rb
|
|
129
|
-
- spec/travis_build.sh
|
|
130
|
-
- spec/webp_ffi_spec.rb
|
|
131
|
-
- webp-ffi.gemspec
|
|
129
|
+
- sig/webp.rbs
|
|
132
130
|
homepage: http://leopard.in.ua/webp-ffi
|
|
133
131
|
licenses:
|
|
134
132
|
- MIT
|
|
135
133
|
metadata: {}
|
|
136
|
-
post_install_message:
|
|
137
134
|
rdoc_options: []
|
|
138
135
|
require_paths:
|
|
139
136
|
- lib
|
|
@@ -141,28 +138,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
141
138
|
requirements:
|
|
142
139
|
- - ">="
|
|
143
140
|
- !ruby/object:Gem::Version
|
|
144
|
-
version: '
|
|
141
|
+
version: '3.2'
|
|
145
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
143
|
requirements:
|
|
147
144
|
- - ">="
|
|
148
145
|
- !ruby/object:Gem::Version
|
|
149
146
|
version: '0'
|
|
150
147
|
requirements: []
|
|
151
|
-
rubygems_version:
|
|
152
|
-
signing_key:
|
|
148
|
+
rubygems_version: 4.0.20
|
|
153
149
|
specification_version: 4
|
|
154
150
|
summary: Ruby wrapper for libwebp
|
|
155
|
-
test_files:
|
|
156
|
-
- spec/factories/1.png
|
|
157
|
-
- spec/factories/1.webp
|
|
158
|
-
- spec/factories/2.png
|
|
159
|
-
- spec/factories/2.webp
|
|
160
|
-
- spec/factories/3.jpg
|
|
161
|
-
- spec/factories/3.webp
|
|
162
|
-
- spec/factories/4.jpg
|
|
163
|
-
- spec/factories/4.webp
|
|
164
|
-
- spec/factories/5.tif
|
|
165
|
-
- spec/factories/5.webp
|
|
166
|
-
- spec/spec_helper.rb
|
|
167
|
-
- spec/travis_build.sh
|
|
168
|
-
- spec/webp_ffi_spec.rb
|
|
151
|
+
test_files: []
|
data/.gitignore
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
*.gem
|
|
2
|
-
*.rbc
|
|
3
|
-
.bundle
|
|
4
|
-
.config
|
|
5
|
-
.yardoc
|
|
6
|
-
.DS_Store
|
|
7
|
-
Gemfile.lock
|
|
8
|
-
InstalledFiles
|
|
9
|
-
_yardoc
|
|
10
|
-
coverage
|
|
11
|
-
doc/
|
|
12
|
-
lib/bundler/man
|
|
13
|
-
pkg
|
|
14
|
-
rdoc
|
|
15
|
-
spec/reports
|
|
16
|
-
test/tmp
|
|
17
|
-
test/version_tmp
|
|
18
|
-
tmp
|
|
19
|
-
ext/webp_ffi/x86_64-darwin/
|
|
20
|
-
ext/webp_ffi/x86_64-linux/
|
|
21
|
-
.vagrant
|
|
22
|
-
Vagrantfile
|
data/.ruby-version
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
2.7.1
|
data/.travis.yml
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
language: ruby
|
|
2
|
-
|
|
3
|
-
before_install:
|
|
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
|
-
|
|
9
|
-
rvm:
|
|
10
|
-
- 2.5
|
|
11
|
-
- 2.6
|
|
12
|
-
- 2.7
|
|
13
|
-
- 3.0
|
|
14
|
-
- jruby-19mode
|
|
15
|
-
- rbx-19mode
|
|
16
|
-
- ruby-head
|
|
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
|
-
|
|
26
|
-
notifications:
|
|
27
|
-
email: false
|
|
28
|
-
|
|
29
|
-
branches:
|
|
30
|
-
only:
|
|
31
|
-
- master
|
|
32
|
-
- development
|
|
33
|
-
|
|
34
|
-
matrix:
|
|
35
|
-
allow_failures:
|
|
36
|
-
- rvm: rbx-19mode
|
|
37
|
-
- rvm: ruby-head
|
|
38
|
-
- rvm: jruby-head
|
data/Gemfile
DELETED
data/Rakefile
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
require 'rubygems'
|
|
2
|
-
require 'bundler/setup'
|
|
3
|
-
require 'rake'
|
|
4
|
-
require 'rake/clean'
|
|
5
|
-
require 'bundler/gem_tasks'
|
|
6
|
-
require 'rspec/core/rake_task'
|
|
7
|
-
require 'ffi-compiler/compile_task'
|
|
8
|
-
|
|
9
|
-
desc "compiler tasks"
|
|
10
|
-
namespace "ffi-compiler" do
|
|
11
|
-
FFI::Compiler::CompileTask.new('ext/webp_ffi/webp_ffi') do |c|
|
|
12
|
-
c.have_header?('stdio.h', '/usr/local/include')
|
|
13
|
-
c.have_func?('puts')
|
|
14
|
-
c.have_library?('z')
|
|
15
|
-
c.have_header?('decode.h', '/usr/local/include')
|
|
16
|
-
c.have_header?('encode.h', '/usr/local/include')
|
|
17
|
-
c.have_func?('WebPDecoderConfig')
|
|
18
|
-
c.have_func?('WebPGetInfo')
|
|
19
|
-
c.have_library?('webp')
|
|
20
|
-
c.have_library?('png')
|
|
21
|
-
c.have_library?('jpeg')
|
|
22
|
-
c.have_library?('tiff')
|
|
23
|
-
c.ldflags << ENV['LD_FLAGS'] if ENV['LD_FLAGS']
|
|
24
|
-
c.cflags << ENV['C_FLAGS'] if ENV['C_FLAGS']
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
task :compile => ["ffi-compiler:default"]
|
|
28
|
-
|
|
29
|
-
desc "run specs"
|
|
30
|
-
task :spec do
|
|
31
|
-
RSpec::Core::RakeTask.new
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
task :default => [:clean, :compile, :spec]
|
|
35
|
-
|
|
36
|
-
CLEAN.include('ext/**/*{.o,.log,.so,.bundle}')
|
|
37
|
-
CLEAN.include('lib/**/*{.o,.log,.so,.bundle}')
|
|
38
|
-
CLEAN.include('ext/**/Makefile')
|
data/lib/webp/libc.rb
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
module WebP
|
|
2
|
-
module LibC
|
|
3
|
-
extend FFI::Library
|
|
4
|
-
# figures out the correct libc for each platform including Windows
|
|
5
|
-
library = ffi_lib(FFI::Library::LIBC).first
|
|
6
|
-
|
|
7
|
-
# Size_t not working properly on Windows
|
|
8
|
-
find_type(:size_t) rescue typedef(:ulong, :size_t)
|
|
9
|
-
|
|
10
|
-
# memory allocators
|
|
11
|
-
attach_function :malloc, [:size_t], :pointer
|
|
12
|
-
attach_function :free, [:pointer], :void
|
|
13
|
-
|
|
14
|
-
# get a pointer to the free function
|
|
15
|
-
Free = library.find_symbol('free')
|
|
16
|
-
|
|
17
|
-
# memory movers
|
|
18
|
-
attach_function :memcpy, [:pointer, :pointer, :size_t], :pointer
|
|
19
|
-
end # module LibC
|
|
20
|
-
end
|
data/spec/factories/1.png
DELETED
|
Binary file
|
data/spec/factories/1.webp
DELETED
|
Binary file
|
data/spec/factories/2.png
DELETED
|
Binary file
|
data/spec/factories/2.webp
DELETED
|
Binary file
|
data/spec/factories/3.jpg
DELETED
|
Binary file
|
data/spec/factories/3.webp
DELETED
|
Binary file
|
data/spec/factories/4.jpg
DELETED
|
Binary file
|
data/spec/factories/4.webp
DELETED
|
Binary file
|
data/spec/factories/5.tif
DELETED
|
Binary file
|
data/spec/factories/5.webp
DELETED
|
Binary file
|
data/spec/spec_helper.rb
DELETED
data/spec/travis_build.sh
DELETED
data/spec/webp_ffi_spec.rb
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe WebP do
|
|
4
|
-
factories = {
|
|
5
|
-
webp: ["1", "2", "3", "4", "5"],
|
|
6
|
-
png: ["1", "2"],
|
|
7
|
-
jpg: ["3", "4"],
|
|
8
|
-
tiff: ["5"],
|
|
9
|
-
info: {
|
|
10
|
-
"1" => {
|
|
11
|
-
size: [400, 301],
|
|
12
|
-
has_alpha: true
|
|
13
|
-
},
|
|
14
|
-
"2" => {
|
|
15
|
-
size: [386, 395],
|
|
16
|
-
has_alpha: true
|
|
17
|
-
},
|
|
18
|
-
"3" => {
|
|
19
|
-
size: [550, 368],
|
|
20
|
-
has_alpha: false
|
|
21
|
-
},
|
|
22
|
-
"4" => {
|
|
23
|
-
size: [1024, 772],
|
|
24
|
-
has_alpha: false
|
|
25
|
-
},
|
|
26
|
-
"5" => {
|
|
27
|
-
size: [1419, 1001],
|
|
28
|
-
has_alpha: false
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
before :all do
|
|
34
|
-
@out_dir = File.expand_path(File.join(File.dirname(__FILE__), "../tmp/"))
|
|
35
|
-
Dir.mkdir(@out_dir) unless File.exists?(@out_dir)
|
|
36
|
-
end
|
|
37
|
-
after :all do
|
|
38
|
-
@out_dir = File.expand_path(File.join(File.dirname(__FILE__), "../tmp/"))
|
|
39
|
-
Dir["#{@out_dir}/*{.png,.webp}"].each do |file|
|
|
40
|
-
File.delete(file) rescue nil
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it "calculate plus 100 by test_c (verify C)" do
|
|
45
|
-
expect(WebP::C.test_c(100)).to eq(200)
|
|
46
|
-
expect(WebP::C.test_c(150)).to eq(250)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
it "decoder version" do
|
|
50
|
-
expect(WebP.decoder_version).not_to be_nil
|
|
51
|
-
expect(WebP.decoder_version).to match(/^([0-9]+)\.([0-9]+)\.([0-9]+)$/)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
it "encoder version" do
|
|
55
|
-
expect(WebP.encoder_version).not_to be_nil
|
|
56
|
-
expect(WebP.decoder_version).to match(/^([0-9]+)\.([0-9]+)\.([0-9]+)$/)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
context "webp_size" do
|
|
60
|
-
factories[:webp].each do |image|
|
|
61
|
-
it "#{image} image size == #{factories[:info][image][:size]}" do
|
|
62
|
-
filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.webp"))
|
|
63
|
-
data = File.open(filename, "rb").read
|
|
64
|
-
info = WebP.webp_size(data)
|
|
65
|
-
expect(info.class).to eq(Array)
|
|
66
|
-
expect(info.size).to eq(2)
|
|
67
|
-
expect(info).to eq(factories[:info][image][:size])
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
it "raise InvalidImageFormatError for non-webp image" do
|
|
71
|
-
filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/1.png"))
|
|
72
|
-
data = File.open(filename, "rb").read
|
|
73
|
-
expect { WebP.webp_size(data) }.to raise_error WebP::InvalidImageFormatError
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
context "encode" do
|
|
78
|
-
factories[:png].each do |image|
|
|
79
|
-
it "#{image}.png image" do
|
|
80
|
-
in_filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.png"))
|
|
81
|
-
out_filename = File.expand_path(File.join(@out_dir, "#{image}.png.webp"))
|
|
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
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
factories[:jpg].each do |image|
|
|
92
|
-
it "#{image}.jpg image" do
|
|
93
|
-
in_filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.jpg"))
|
|
94
|
-
out_filename = File.expand_path(File.join(@out_dir, "#{image}.jpg.webp"))
|
|
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
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
factories[:tiff].each do |image|
|
|
105
|
-
it "#{image}.tif image" do
|
|
106
|
-
in_filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.tif"))
|
|
107
|
-
out_filename = File.expand_path(File.join(@out_dir, "#{image}.tif.webp"))
|
|
108
|
-
expect(WebP.encode(in_filename, out_filename)).to be_truthy
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
factories[:webp].each do |image|
|
|
112
|
-
it "raise EncoderError on #{image}.webp image" do
|
|
113
|
-
in_filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.webp"))
|
|
114
|
-
out_filename = File.expand_path(File.join(@out_dir, "#{image}invalid.webp.png"))
|
|
115
|
-
expect { WebP.encode(in_filename, out_filename) }.to raise_error WebP::EncoderError
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
context "with options" do
|
|
119
|
-
factories[:png].each do |image|
|
|
120
|
-
it "#{image}.png image" do
|
|
121
|
-
in_filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.png"))
|
|
122
|
-
out_filename = File.expand_path(File.join(@out_dir, "#{image}.50png.webp"))
|
|
123
|
-
WebP.encode(in_filename, out_filename, quality: 50, method: 0, alpha_quality: 10, alpha_compression: 1)
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
|
-
end
|
|
127
|
-
context "raise EncoderError on invalid crop options" do
|
|
128
|
-
factories[:png].each do |image|
|
|
129
|
-
it "#{image}.png image" do
|
|
130
|
-
in_filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.png"))
|
|
131
|
-
out_filename = File.expand_path(File.join(@out_dir, "#{image}.invpng.webp"))
|
|
132
|
-
expect { WebP.encode(in_filename, out_filename, crop_w: 30000) }.to raise_error WebP::EncoderError, /crop/i
|
|
133
|
-
end
|
|
134
|
-
end
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
context "decode" do
|
|
139
|
-
factories[:webp].each do |image|
|
|
140
|
-
it "#{image}.webp image" do
|
|
141
|
-
in_filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.webp"))
|
|
142
|
-
out_filename = File.expand_path(File.join(@out_dir, "#{image}.webp.png"))
|
|
143
|
-
expect(WebP.decode(in_filename, out_filename)).to be_truthy
|
|
144
|
-
end
|
|
145
|
-
end
|
|
146
|
-
context "with output_format" do
|
|
147
|
-
[:png, :pam, :ppm, :pgm, :bmp, :tiff, :yuv, :alpha_plane_only].each do |output_format|
|
|
148
|
-
factories[:webp].take(2).each do |image|
|
|
149
|
-
it "#{image}.webp image to #{output_format}" do
|
|
150
|
-
in_filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.webp"))
|
|
151
|
-
out_filename = File.expand_path(File.join(@out_dir, "#{image}.#{output_format}.png"))
|
|
152
|
-
expect(WebP.decode(in_filename, out_filename, output_format: output_format)).to be_truthy
|
|
153
|
-
end
|
|
154
|
-
end
|
|
155
|
-
end
|
|
156
|
-
end
|
|
157
|
-
context "with options" do
|
|
158
|
-
factories[:webp].take(2).each do |image|
|
|
159
|
-
it "#{image}.webp image to png and crop" do
|
|
160
|
-
in_filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.webp"))
|
|
161
|
-
out_filename = File.expand_path(File.join(@out_dir, "#{image}_crop.png"))
|
|
162
|
-
expect(WebP.decode(in_filename, out_filename, crop_w: 200, crop_h: 200)).to be_truthy
|
|
163
|
-
end
|
|
164
|
-
it "#{image}.webp image to png and scale" do
|
|
165
|
-
in_filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.webp"))
|
|
166
|
-
out_filename = File.expand_path(File.join(@out_dir, "#{image}_resize.png"))
|
|
167
|
-
expect(WebP.decode(in_filename, out_filename, resize_w: 200, resize_h: 200)).to be_truthy
|
|
168
|
-
end
|
|
169
|
-
end
|
|
170
|
-
end
|
|
171
|
-
context "raise DecoderError on invalid webp image" do
|
|
172
|
-
factories[:png].each do |image|
|
|
173
|
-
it "#{image}.png image" do
|
|
174
|
-
in_filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.png"))
|
|
175
|
-
out_filename = File.expand_path(File.join(@out_dir, "#{image}.invpng.webp"))
|
|
176
|
-
expect { WebP.decode(in_filename, out_filename) }.to raise_error WebP::DecoderError, /invalid webp/i
|
|
177
|
-
end
|
|
178
|
-
end
|
|
179
|
-
end
|
|
180
|
-
context "raise DecoderError on invalid options" do
|
|
181
|
-
factories[:png].each do |image|
|
|
182
|
-
it "#{image}.png image" do
|
|
183
|
-
in_filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.webp"))
|
|
184
|
-
out_filename = File.expand_path(File.join(@out_dir, "#{image}.png"))
|
|
185
|
-
expect { WebP.decode(in_filename, out_filename, crop_w: 30000) }.to raise_error WebP::DecoderError, /decoding failed/i
|
|
186
|
-
end
|
|
187
|
-
end
|
|
188
|
-
end
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
end
|
data/webp-ffi.gemspec
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# coding: utf-8
|
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
-
require 'webp/version'
|
|
5
|
-
|
|
6
|
-
Gem::Specification.new do |spec|
|
|
7
|
-
spec.name = "webp-ffi"
|
|
8
|
-
spec.version = WebP::VERSION
|
|
9
|
-
spec.authors = ["Alexey Vasyliev"]
|
|
10
|
-
spec.email = ["leopard.not.a@gmail.com"]
|
|
11
|
-
spec.description = %q{Ruby wrapper for libwebp}
|
|
12
|
-
spec.summary = %q{Ruby wrapper for libwebp}
|
|
13
|
-
spec.homepage = "http://leopard.in.ua/webp-ffi"
|
|
14
|
-
spec.license = "MIT"
|
|
15
|
-
|
|
16
|
-
spec.files = `git ls-files`.split($/)
|
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
-
spec.require_paths = ["lib"]
|
|
20
|
-
spec.extensions << 'ext/webp_ffi/Rakefile'
|
|
21
|
-
|
|
22
|
-
spec.add_runtime_dependency "ffi", ">= 1.9.0"
|
|
23
|
-
spec.add_runtime_dependency "ffi-compiler", ">= 0.1.2"
|
|
24
|
-
|
|
25
|
-
spec.add_development_dependency "bundler", ">= 1.2"
|
|
26
|
-
spec.add_development_dependency "rake"
|
|
27
|
-
spec.add_development_dependency "rspec", ">= 3"
|
|
28
|
-
end
|