webp-ffi 0.0.1
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.
- data/.gitignore +21 -0
- data/.rvmrc +1 -0
- data/.travis.yml +21 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +32 -0
- data/Rakefile +34 -0
- data/ext/webp_ffi/Rakefile +16 -0
- data/ext/webp_ffi/util.c +49 -0
- data/ext/webp_ffi/util.h +15 -0
- data/ext/webp_ffi/webp_ffi.c +59 -0
- data/ext/webp_ffi/webp_ffi.h +18 -0
- data/lib/webp-ffi.rb +1 -0
- data/lib/webp_ffi.rb +14 -0
- data/lib/webp_ffi/c.rb +27 -0
- data/lib/webp_ffi/error.rb +3 -0
- data/lib/webp_ffi/version.rb +3 -0
- data/lib/webp_ffi/webp_ffi.rb +46 -0
- data/spec/bindings.md +19 -0
- 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.png +0 -0
- data/spec/factories/3.webp +0 -0
- data/spec/factories/4.png +0 -0
- data/spec/factories/4.webp +0 -0
- data/spec/factories/5.jpg +0 -0
- data/spec/factories/5.webp +0 -0
- data/spec/factories/6.jpg +0 -0
- data/spec/factories/6.webp +0 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/travis_build.sh +8 -0
- data/spec/webp_ffi_spec.rb +78 -0
- data/webp-ffi.gemspec +29 -0
- metadata +184 -0
data/.gitignore
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
ext/webp_ffi/x86_64-darwin/
|
19
|
+
ext/webp_ffi/x86_64-linux/
|
20
|
+
.vagrant
|
21
|
+
Vagrantfile
|
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm ruby-2.0.0-p0
|
data/.travis.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
language: ruby
|
2
|
+
before_install:
|
3
|
+
- ./spec/travis_build.sh
|
4
|
+
rvm:
|
5
|
+
- 1.9.2
|
6
|
+
- 1.9.3
|
7
|
+
- 2.0.0
|
8
|
+
- jruby-19mode
|
9
|
+
- rbx-19mode
|
10
|
+
- ruby-head
|
11
|
+
- jruby-head
|
12
|
+
notifications:
|
13
|
+
email: false
|
14
|
+
branches:
|
15
|
+
only:
|
16
|
+
- master
|
17
|
+
- development
|
18
|
+
matrix:
|
19
|
+
allow_failures:
|
20
|
+
- rvm: ruby-head
|
21
|
+
- rvm: jruby-head
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Alexey Vasyliev
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Webp-ffi
|
2
|
+
|
3
|
+
[](https://travis-ci.org/le0pard/webp-ffi)
|
4
|
+
[](https://codeclimate.com/github/le0pard/webp-ffi)
|
5
|
+
|
6
|
+
Ruby wrapper for libwebp.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'webp-ffi'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install webp-ffi
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
TODO: Write usage instructions here
|
25
|
+
|
26
|
+
## Contributing
|
27
|
+
|
28
|
+
1. Fork it
|
29
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
30
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
31
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
32
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/clean'
|
4
|
+
require 'bundler/gem_tasks'
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
require 'ffi-compiler/compile_task'
|
7
|
+
|
8
|
+
desc "compiler tasks"
|
9
|
+
namespace "ffi-compiler" do
|
10
|
+
FFI::Compiler::CompileTask.new('ext/webp_ffi/webp_ffi') do |c|
|
11
|
+
c.have_header?('stdio.h', '/usr/local/include')
|
12
|
+
c.have_func?('puts')
|
13
|
+
c.have_library?('z')
|
14
|
+
c.have_header?('decode.h', '/usr/local/include')
|
15
|
+
c.have_header?('encode.h', '/usr/local/include')
|
16
|
+
c.have_func?('WebPDecoderConfig')
|
17
|
+
c.have_func?('WebPGetInfo')
|
18
|
+
c.have_library?('webp')
|
19
|
+
c.cflags << "-arch x86_64" if c.platform.mac?
|
20
|
+
c.ldflags << "-arch x86_64" if c.platform.mac?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
task :compile => ["ffi-compiler:default"]
|
24
|
+
|
25
|
+
desc "run specs"
|
26
|
+
task :spec do
|
27
|
+
RSpec::Core::RakeTask.new
|
28
|
+
end
|
29
|
+
|
30
|
+
task :default => [:clean, :compile, :spec]
|
31
|
+
|
32
|
+
CLEAN.include('ext/**/*{.o,.log,.so,.bundle}')
|
33
|
+
CLEAN.include('lib/**/*{.o,.log,.so,.bundle}')
|
34
|
+
CLEAN.include('ext/**/Makefile')
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'ffi-compiler/compile_task'
|
2
|
+
|
3
|
+
FFI::Compiler::CompileTask.new('webp_ffi') do |c|
|
4
|
+
c.have_header?('stdio.h', '/usr/local/include')
|
5
|
+
c.have_func?('puts')
|
6
|
+
c.have_library?('z')
|
7
|
+
# webp
|
8
|
+
c.have_header?('decode.h', '/usr/local/include')
|
9
|
+
c.have_header?('encode.h', '/usr/local/include')
|
10
|
+
c.have_func?('WebPDecoderConfig')
|
11
|
+
c.have_func?('WebPGetInfo')
|
12
|
+
c.have_library?('webp')
|
13
|
+
# compiler flags
|
14
|
+
c.cflags << "-arch x86_64 -arch i386" if c.platform.mac?
|
15
|
+
c.ldflags << "-arch x86_64 -arch i386" if c.platform.mac?
|
16
|
+
end
|
data/ext/webp_ffi/util.c
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
#include "./util.h"
|
2
|
+
#include <stdio.h>
|
3
|
+
#include <stdlib.h>
|
4
|
+
|
5
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
6
|
+
extern "C" {
|
7
|
+
#endif
|
8
|
+
|
9
|
+
// -----------------------------------------------------------------------------
|
10
|
+
// File I/O
|
11
|
+
|
12
|
+
int WebpFfiReadFile(const char* const file_name,
|
13
|
+
const uint8_t** data, size_t* data_size) {
|
14
|
+
int ok;
|
15
|
+
void* file_data;
|
16
|
+
size_t file_size;
|
17
|
+
FILE* in;
|
18
|
+
|
19
|
+
if (file_name == NULL || data == NULL || data_size == NULL) return 0;
|
20
|
+
*data = NULL;
|
21
|
+
*data_size = 0;
|
22
|
+
|
23
|
+
in = fopen(file_name, "rb");
|
24
|
+
if (in == NULL) {
|
25
|
+
fprintf(stderr, "cannot open input file '%s'\n", file_name);
|
26
|
+
return 0;
|
27
|
+
}
|
28
|
+
fseek(in, 0, SEEK_END);
|
29
|
+
file_size = ftell(in);
|
30
|
+
fseek(in, 0, SEEK_SET);
|
31
|
+
file_data = malloc(file_size);
|
32
|
+
if (file_data == NULL) return 0;
|
33
|
+
ok = (fread(file_data, file_size, 1, in) == 1);
|
34
|
+
fclose(in);
|
35
|
+
|
36
|
+
if (!ok) {
|
37
|
+
fprintf(stderr, "Could not read %zu bytes of data from file %s\n",
|
38
|
+
file_size, file_name);
|
39
|
+
free(file_data);
|
40
|
+
return 0;
|
41
|
+
}
|
42
|
+
*data = (uint8_t*)file_data;
|
43
|
+
*data_size = file_size;
|
44
|
+
return 1;
|
45
|
+
}
|
46
|
+
|
47
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
48
|
+
} // extern "C"
|
49
|
+
#endif
|
data/ext/webp_ffi/util.h
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#include "webp/types.h"
|
2
|
+
|
3
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
4
|
+
extern "C" {
|
5
|
+
#endif
|
6
|
+
|
7
|
+
// Allocates storage for entire file 'file_name' and returns contents and size
|
8
|
+
// in 'data' and 'data_size'. Returns 1 on success, 0 otherwise. '*data' should
|
9
|
+
// be deleted using free().
|
10
|
+
int WebpFfiReadFile(const char* const file_name,
|
11
|
+
const uint8_t** data, size_t* data_size);
|
12
|
+
|
13
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
14
|
+
} // extern "C"
|
15
|
+
#endif
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#include <assert.h>
|
2
|
+
#include <stdio.h>
|
3
|
+
#include <stdlib.h>
|
4
|
+
#include <string.h>
|
5
|
+
|
6
|
+
#include "webp/decode.h"
|
7
|
+
#include "webp/encode.h"
|
8
|
+
|
9
|
+
// utils
|
10
|
+
#include "./util.h"
|
11
|
+
#include "./webp_ffi.h"
|
12
|
+
|
13
|
+
#ifdef WEBP_HAVE_PNG
|
14
|
+
#include <png.h>
|
15
|
+
#endif
|
16
|
+
|
17
|
+
#ifdef WEBP_HAVE_JPEG
|
18
|
+
#include <setjmp.h> // note: this must be included *after* png.h
|
19
|
+
#include <jpeglib.h>
|
20
|
+
#endif
|
21
|
+
|
22
|
+
#ifdef WEBP_HAVE_TIFF
|
23
|
+
#include <tiffio.h>
|
24
|
+
#endif
|
25
|
+
|
26
|
+
|
27
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
28
|
+
extern "C" {
|
29
|
+
#endif
|
30
|
+
|
31
|
+
void decoder_version(char *version) {
|
32
|
+
int v = WebPGetDecoderVersion();
|
33
|
+
sprintf(version, "%d.%d.%d",
|
34
|
+
(v >> 16) & 0xff, (v >> 8) & 0xff, v & 0xff);
|
35
|
+
}
|
36
|
+
|
37
|
+
void encoder_version(char *version) {
|
38
|
+
int v = WebPGetEncoderVersion();
|
39
|
+
sprintf(version, "%d.%d.%d",
|
40
|
+
(v >> 16) & 0xff, (v >> 8) & 0xff, v & 0xff);
|
41
|
+
}
|
42
|
+
|
43
|
+
int webp_get_info(const uint8_t* data, size_t data_size, int* width, int* height) {
|
44
|
+
return WebPGetInfo(data, data_size, width, height);
|
45
|
+
}
|
46
|
+
|
47
|
+
uint8_t* webp_decode_rgba(const uint8_t* data, size_t data_size, int* width, int* height) {
|
48
|
+
return WebPDecodeRGBA(data, data_size, width, height);
|
49
|
+
}
|
50
|
+
|
51
|
+
// test
|
52
|
+
int test(int n) {
|
53
|
+
return n + 100;
|
54
|
+
}
|
55
|
+
|
56
|
+
|
57
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
58
|
+
} // extern "C"
|
59
|
+
#endif
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#ifndef _WEBP_FFI_H_
|
2
|
+
#define _WEBP_FFI_H_
|
3
|
+
|
4
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
5
|
+
extern "C" {
|
6
|
+
#endif
|
7
|
+
|
8
|
+
void decoder_version(char *version);
|
9
|
+
void encoder_version(char *version);
|
10
|
+
int webp_get_info(const uint8_t* data, size_t data_size, int* width, int* height);
|
11
|
+
uint8_t* webp_decode_rgba(const uint8_t* data, size_t data_size, int* width, int* height);
|
12
|
+
int test(int n);
|
13
|
+
|
14
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
15
|
+
} // extern "C"
|
16
|
+
#endif
|
17
|
+
|
18
|
+
#endif /* _WEBP_FFI_H_ */
|
data/lib/webp-ffi.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "webp_ffi"
|
data/lib/webp_ffi.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
require 'ffi-compiler/loader'
|
3
|
+
|
4
|
+
module WebpFfi
|
5
|
+
module C
|
6
|
+
extend FFI::Library
|
7
|
+
ffi_lib FFI::Compiler::Loader.find('webp_ffi')
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
require "webp_ffi/c"
|
12
|
+
require "webp_ffi/error"
|
13
|
+
require "webp_ffi/webp_ffi"
|
14
|
+
require "webp_ffi/version"
|
data/lib/webp_ffi/c.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module WebpFfi
|
2
|
+
module C
|
3
|
+
# enum
|
4
|
+
vp8_status_code_enum = enum(:vp8_status_ok, 0,
|
5
|
+
:vp8_status_out_of_memory,
|
6
|
+
:vp8_status_invalid_params,
|
7
|
+
:vp8_status_bitstream_error,
|
8
|
+
:vp8_status_unsupported_feature,
|
9
|
+
:vp8_status_suspended,
|
10
|
+
:vp8_status_user_abort,
|
11
|
+
:vp8_status_not_enought_data)
|
12
|
+
# struct
|
13
|
+
class WebPBitstreamFeatures < FFI::Struct
|
14
|
+
layout :width, :int,
|
15
|
+
:height, :int,
|
16
|
+
:has_alpha, :int
|
17
|
+
end
|
18
|
+
|
19
|
+
# webp lib functions
|
20
|
+
attach_function :decoder_version, [:pointer], :void
|
21
|
+
attach_function :encoder_version, [:pointer], :void
|
22
|
+
attach_function :webp_get_info, [:pointer, :size_t, :pointer, :pointer], :int
|
23
|
+
attach_function :webp_decode_rgba, [:pointer, :size_t, :pointer, :pointer], :pointer
|
24
|
+
|
25
|
+
attach_function :test, [:int], :int
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "webp_ffi/c"
|
2
|
+
|
3
|
+
module WebpFfi
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def decoder_version
|
7
|
+
pointer = FFI::MemoryPointer.new(:char, 10)
|
8
|
+
C.decoder_version(pointer)
|
9
|
+
pointer.null? ? nil : pointer.read_string()
|
10
|
+
end
|
11
|
+
|
12
|
+
def encoder_version
|
13
|
+
pointer = FFI::MemoryPointer.new(:char, 10)
|
14
|
+
C.encoder_version(pointer)
|
15
|
+
pointer.null? ? nil : pointer.read_string()
|
16
|
+
end
|
17
|
+
|
18
|
+
# get webp image size
|
19
|
+
def webp_size(data)
|
20
|
+
return nil if data.nil?
|
21
|
+
width_ptr = FFI::MemoryPointer.new(:int, 2)
|
22
|
+
height_ptr = FFI::MemoryPointer.new(:int, 2)
|
23
|
+
size = data.respond_to?(:bytesize) ? data.bytesize : data.size
|
24
|
+
memBuf = FFI::MemoryPointer.new(:char, size)
|
25
|
+
memBuf.put_bytes(0, data)
|
26
|
+
if C.webp_get_info(memBuf, size, width_ptr, height_ptr) == 1
|
27
|
+
[width_ptr.null? ? nil : width_ptr.read_int, height_ptr.null? ? nil : height_ptr.read_int]
|
28
|
+
else
|
29
|
+
raise InvalidImageFormatError, "invalid webp image"
|
30
|
+
return nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def webp_decode_rgba(data)
|
35
|
+
return nil if data.nil?
|
36
|
+
width_ptr = FFI::MemoryPointer.new(:int, 2)
|
37
|
+
height_ptr = FFI::MemoryPointer.new(:int, 2)
|
38
|
+
size = data.respond_to?(:bytesize) ? data.bytesize : data.size
|
39
|
+
memBuf = FFI::MemoryPointer.new(:char, size)
|
40
|
+
memBuf.put_bytes(0, data)
|
41
|
+
pointer = C.webp_decode_rgba(memBuf, size, width_ptr, height_ptr)
|
42
|
+
pointer.null? ? nil : pointer.read_string()
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
data/spec/bindings.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Decode:
|
2
|
+
WebPGetDecoderVersion
|
3
|
+
WebPGetInfo
|
4
|
+
WebPDecodeRGBA
|
5
|
+
WebPDecodeARGB
|
6
|
+
WebPDecodeBGRA
|
7
|
+
WebPDecodeBGR
|
8
|
+
WebPDecodeRGB
|
9
|
+
|
10
|
+
Encode:
|
11
|
+
WebPGetEncoderVersion
|
12
|
+
WebPEncodeRGBA
|
13
|
+
WebPEncodeBGRA
|
14
|
+
WebPEncodeRGB
|
15
|
+
WebPEncodeBGR
|
16
|
+
WebPEncodeLosslessRGBA
|
17
|
+
WebPEncodeLosslessBGRA
|
18
|
+
WebPEncodeLosslessRGB
|
19
|
+
WebPEncodeLosslessBGR
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WebpFfi do
|
4
|
+
factories = {
|
5
|
+
webp: ["1.webp", "2.webp", "3.webp", "4.webp", "5.webp", "6.webp"],
|
6
|
+
info: {
|
7
|
+
"1.webp" => {
|
8
|
+
size: [400, 301],
|
9
|
+
has_alpha: true
|
10
|
+
},
|
11
|
+
"2.webp" => {
|
12
|
+
size: [386, 395],
|
13
|
+
has_alpha: true
|
14
|
+
},
|
15
|
+
"3.webp" => {
|
16
|
+
size: [300, 300],
|
17
|
+
has_alpha: true
|
18
|
+
},
|
19
|
+
"4.webp" => {
|
20
|
+
size: [2000, 2353],
|
21
|
+
has_alpha: true
|
22
|
+
},
|
23
|
+
"5.webp" => {
|
24
|
+
size: [550, 368],
|
25
|
+
has_alpha: false
|
26
|
+
},
|
27
|
+
"6.webp" => {
|
28
|
+
size: [1024, 772],
|
29
|
+
has_alpha: false
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
it "calculate plus 100 by test" do
|
35
|
+
WebpFfi::C.test(100).should == 200
|
36
|
+
WebpFfi::C.test(150).should == 250
|
37
|
+
end
|
38
|
+
|
39
|
+
it "decoder version" do
|
40
|
+
WebpFfi.decoder_version.should_not be_nil
|
41
|
+
WebpFfi.decoder_version.should =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)$/
|
42
|
+
end
|
43
|
+
|
44
|
+
it "encoder version" do
|
45
|
+
WebpFfi.encoder_version.should_not be_nil
|
46
|
+
WebpFfi.decoder_version.should =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)$/
|
47
|
+
end
|
48
|
+
|
49
|
+
context "webp_size" do
|
50
|
+
factories[:webp].each do |image|
|
51
|
+
it "#{image} image size == #{factories[:info][image][:size]}" do
|
52
|
+
filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}"))
|
53
|
+
data = File.open(filename, "rb").read
|
54
|
+
info = WebpFfi.webp_size(data)
|
55
|
+
info.class.should == Array
|
56
|
+
info.size.should == 2
|
57
|
+
info.should == factories[:info][image][:size]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
it "raise InvalidImageFormatError for non-webp image" do
|
61
|
+
filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/1.png"))
|
62
|
+
data = File.open(filename, "rb").read
|
63
|
+
expect { WebpFfi.webp_size(data) }.to raise_error WebpFfi::InvalidImageFormatError
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "webp_decode_rgba" do
|
68
|
+
factories[:webp].each do |image|
|
69
|
+
it "#{image} webp_decode_rgba" do
|
70
|
+
filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}"))
|
71
|
+
data = File.open(filename, "rb").read
|
72
|
+
output_data = WebpFfi.webp_decode_rgba(data)
|
73
|
+
# TODO: finish
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
data/webp-ffi.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'webp_ffi/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "webp-ffi"
|
8
|
+
spec.version = WebpFfi::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.4.0"
|
23
|
+
#spec.add_runtime_dependency "ffi-compiler", "~> 0.1.1"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", ">= 1.2"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
spec.add_development_dependency "rspec"
|
28
|
+
spec.add_development_dependency "vagrant"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: webp-ffi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Alexey Vasyliev
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: ffi
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.4.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.4.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.2'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.2'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: vagrant
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: Ruby wrapper for libwebp
|
95
|
+
email:
|
96
|
+
- leopard.not.a@gmail.com
|
97
|
+
executables: []
|
98
|
+
extensions:
|
99
|
+
- ext/webp_ffi/Rakefile
|
100
|
+
extra_rdoc_files: []
|
101
|
+
files:
|
102
|
+
- .gitignore
|
103
|
+
- .rvmrc
|
104
|
+
- .travis.yml
|
105
|
+
- Gemfile
|
106
|
+
- LICENSE.txt
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- ext/webp_ffi/Rakefile
|
110
|
+
- ext/webp_ffi/util.c
|
111
|
+
- ext/webp_ffi/util.h
|
112
|
+
- ext/webp_ffi/webp_ffi.c
|
113
|
+
- ext/webp_ffi/webp_ffi.h
|
114
|
+
- lib/webp-ffi.rb
|
115
|
+
- lib/webp_ffi.rb
|
116
|
+
- lib/webp_ffi/c.rb
|
117
|
+
- lib/webp_ffi/error.rb
|
118
|
+
- lib/webp_ffi/version.rb
|
119
|
+
- lib/webp_ffi/webp_ffi.rb
|
120
|
+
- spec/bindings.md
|
121
|
+
- spec/factories/1.png
|
122
|
+
- spec/factories/1.webp
|
123
|
+
- spec/factories/2.png
|
124
|
+
- spec/factories/2.webp
|
125
|
+
- spec/factories/3.png
|
126
|
+
- spec/factories/3.webp
|
127
|
+
- spec/factories/4.png
|
128
|
+
- spec/factories/4.webp
|
129
|
+
- spec/factories/5.jpg
|
130
|
+
- spec/factories/5.webp
|
131
|
+
- spec/factories/6.jpg
|
132
|
+
- spec/factories/6.webp
|
133
|
+
- spec/spec_helper.rb
|
134
|
+
- spec/travis_build.sh
|
135
|
+
- spec/webp_ffi_spec.rb
|
136
|
+
- webp-ffi.gemspec
|
137
|
+
homepage: http://leopard.in.ua/webp-ffi
|
138
|
+
licenses:
|
139
|
+
- MIT
|
140
|
+
post_install_message:
|
141
|
+
rdoc_options: []
|
142
|
+
require_paths:
|
143
|
+
- lib
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
segments:
|
151
|
+
- 0
|
152
|
+
hash: 488812102417916187
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
none: false
|
155
|
+
requirements:
|
156
|
+
- - '>='
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
segments:
|
160
|
+
- 0
|
161
|
+
hash: 488812102417916187
|
162
|
+
requirements: []
|
163
|
+
rubyforge_project:
|
164
|
+
rubygems_version: 1.8.25
|
165
|
+
signing_key:
|
166
|
+
specification_version: 3
|
167
|
+
summary: Ruby wrapper for libwebp
|
168
|
+
test_files:
|
169
|
+
- spec/bindings.md
|
170
|
+
- spec/factories/1.png
|
171
|
+
- spec/factories/1.webp
|
172
|
+
- spec/factories/2.png
|
173
|
+
- spec/factories/2.webp
|
174
|
+
- spec/factories/3.png
|
175
|
+
- spec/factories/3.webp
|
176
|
+
- spec/factories/4.png
|
177
|
+
- spec/factories/4.webp
|
178
|
+
- spec/factories/5.jpg
|
179
|
+
- spec/factories/5.webp
|
180
|
+
- spec/factories/6.jpg
|
181
|
+
- spec/factories/6.webp
|
182
|
+
- spec/spec_helper.rb
|
183
|
+
- spec/travis_build.sh
|
184
|
+
- spec/webp_ffi_spec.rb
|