diff --git a/CHANGELOG.md b/CHANGELOG.md index 48b462e..32fa872 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## v0.2.6 + +* Tested on webp 1.0.2 +* Added near_lossless option + ## v0.2.5 * Fix build for Travis CI docker containers diff --git a/ext/webp_ffi/webp_ffi.c b/ext/webp_ffi/webp_ffi.c index 5f7dbbf..f8bea25 100644 --- a/ext/webp_ffi/webp_ffi.c +++ b/ext/webp_ffi/webp_ffi.c @@ -64,6 +64,10 @@ int webp_encode(const char *in_file, const char *out_file, const FfiWebpEncodeCo if (encode_config->lossless == 0 || encode_config->lossless == 1){ config.lossless = encode_config->lossless; } + if (encode_config->near_lossless >= 0 && encode_config->near_lossless <= 100){ + config.near_lossless = encode_config->near_lossless; + config.lossless = 1; // use near-lossless only with lossless + } if (encode_config->quality >= 0 && encode_config->quality <= 100){ config.quality = encode_config->quality; } @@ -288,4 +292,4 @@ int test_c(int n) { #if defined(__cplusplus) || defined(c_plusplus) } // extern "C" -#endif \ No newline at end of file +#endif diff --git a/ext/webp_ffi/webp_ffi.h b/ext/webp_ffi/webp_ffi.h index 26f8578..9c54702 100644 --- a/ext/webp_ffi/webp_ffi.h +++ b/ext/webp_ffi/webp_ffi.h @@ -7,6 +7,7 @@ extern "C" { typedef struct { int lossless; // Lossless encoding (0=lossy(default), 1=lossless). + int near_lossless; // use near-lossless image preprocessing (0..100=off) float quality; // between 0 (smallest file) and 100 (biggest) int method; // quality/speed trade-off (0=fast, 6=slower-better) @@ -42,7 +43,7 @@ extern "C" { int crop_x, crop_y, crop_w, crop_h; int resize_w, resize_h; } FfiWebpEncodeConfig; - + typedef struct { OutputFileFormat output_format; int bypass_filtering; // if true, skip the in-loop filtering @@ -51,7 +52,7 @@ extern "C" { int resize_w, resize_h; int use_threads; // if true, use multi-threaded decoding } FfiWebpDecodeConfig; - + void decoder_version(char *version); void encoder_version(char *version); @@ -64,4 +65,4 @@ extern "C" { } // extern "C" #endif -#endif /* _WEBP_FFI_H_ */ \ No newline at end of file +#endif /* _WEBP_FFI_H_ */ diff --git a/lib/webp/c.rb b/lib/webp/c.rb index 04f0499..a726334 100644 --- a/lib/webp/c.rb +++ b/lib/webp/c.rb @@ -12,6 +12,7 @@ module C # struct class FfiWebpEncodeConfig < FFI::Struct layout :lossless, :int, + :near_lossless, :int, :quality, :float, :method, :int, :target_size, :int, diff --git a/lib/webp/options.rb b/lib/webp/options.rb index 0b512fe..b2fc9e4 100644 --- a/lib/webp/options.rb +++ b/lib/webp/options.rb @@ -8,7 +8,7 @@ def initialize(options) def encode_pointer options_pointer = FFI::MemoryPointer.new :char, C::FfiWebpEncodeConfig.size, false options_struct = C::FfiWebpEncodeConfig.new options_pointer - [:lossless, :method, :target_size, :target_PSNR, :segments, + [:lossless, :near_lossless, :method, :target_size, :target_PSNR, :segments, :sns_strength, :filter_strength, :filter_sharpness, :filter_type, :autofilter, :alpha_compression, :alpha_filtering, :alpha_quality, :pass, :show_compressed, :preprocessing, :partitions, diff --git a/lib/webp/version.rb b/lib/webp/version.rb index 9479ce8..5b56e9a 100644 --- a/lib/webp/version.rb +++ b/lib/webp/version.rb @@ -1,3 +1,3 @@ module WebP - VERSION = "1.0.2" + VERSION = "0.2.6" end diff --git a/spec/webp_ffi_spec.rb b/spec/webp_ffi_spec.rb index 04abbf3..017f82f 100644 --- a/spec/webp_ffi_spec.rb +++ b/spec/webp_ffi_spec.rb @@ -35,10 +35,10 @@ Dir.mkdir(@out_dir) unless File.exists?(@out_dir) end after :all do - @out_dir = File.expand_path(File.join(File.dirname(__FILE__), "../tmp/")) - Dir["#{@out_dir}/*{.png,.webp}"].each do |file| - File.delete(file) rescue nil - end + # @out_dir = File.expand_path(File.join(File.dirname(__FILE__), "../tmp/")) + # Dir["#{@out_dir}/*{.png,.webp}"].each do |file| + # File.delete(file) rescue nil + # end end it "calculate plus 100 by test_c (verify C)" do @@ -81,6 +81,12 @@ out_filename = File.expand_path(File.join(@out_dir, "#{image}.png.webp")) expect(WebP.encode(in_filename, out_filename)).to be_truthy end + + it "#{image}.png image with near_lossless" do + in_filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.png")) + out_filename = File.expand_path(File.join(@out_dir, "#{image}_near_lossless.png.webp")) + expect(WebP.encode(in_filename, out_filename, near_lossless: 60)).to be_truthy + end end factories[:jpg].each do |image| it "#{image}.jpg image" do @@ -88,6 +94,12 @@ out_filename = File.expand_path(File.join(@out_dir, "#{image}.jpg.webp")) expect(WebP.encode(in_filename, out_filename)).to be_truthy end + + it "#{image}.jpg image with near_lossless" do + in_filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.jpg")) + out_filename = File.expand_path(File.join(@out_dir, "#{image}_near_lossless.jpg.webp")) + expect(WebP.encode(in_filename, out_filename, near_lossless: 60)).to be_truthy + end end factories[:tiff].each do |image| it "#{image}.tif image" do @@ -176,4 +188,4 @@ end end -end \ No newline at end of file +end