Skip to content

Commit

Permalink
fix formats
Browse files Browse the repository at this point in the history
  • Loading branch information
le0pard committed Jan 17, 2014
1 parent ee16275 commit 88cd376
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v0.2.1

* Fix output for bmp, tiff and yuv

## v0.2.0

* Checked and fixed for webp 0.4.0
Expand Down
26 changes: 13 additions & 13 deletions lib/webp/options.rb
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
module WebP
class Options

def initialize(options)
@user_options = options
end

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,
:sns_strength, :filter_strength, :filter_sharpness,
:filter_type, :autofilter, :alpha_compression, :alpha_filtering,
:alpha_quality, :pass, :show_compressed, :preprocessing, :partitions,
[: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,
:partition_limit, :width, :height].each do |key|
options_struct[key] = @user_options[key] ? @user_options[key] : -1
end
encode_default(options_struct)
[:quality, :crop_x, :crop_y, :crop_w,
[:quality, :crop_x, :crop_y, :crop_w,
:crop_h, :resize_w, :resize_h].each do |key|
options_struct[key] = @user_options[key] if @user_options[key]
end
options_pointer
end

def decode_pointer
options_pointer = FFI::MemoryPointer.new :char, C::FfiWebpDecodeConfig.size, false
options_struct = C::FfiWebpDecodeConfig.new options_pointer
decode_default(options_struct)
# options
if @user_options[:output_format] && [:png, :pam, :ppm, :pgm, :alpha_plane_only].include?(@user_options[:output_format])
if @user_options[:output_format] && [:png, :pam, :ppm, :pgm, :bmp, :tiff, :yuv, :alpha_plane_only].include?(@user_options[:output_format])
options_struct[:output_format] = C::OutputFileFormat[@user_options[:output_format]]
end
[:bypass_filtering, :no_fancy_upsampling, :use_threads].each do |key|
options_struct[key] = 1 if @user_options[key] && true == @user_options[key]
end
[:crop_x, :crop_y, :crop_w,
[:crop_x, :crop_y, :crop_w,
:crop_h, :resize_w, :resize_h].each do |key|
options_struct[key] = @user_options[key] if @user_options[key]
end
options_pointer
end

private

def encode_default(options_struct)
options_struct[:quality] = 100
similar_default(options_struct)
end

def decode_default(options_struct)
# default format is png
options_struct[:output_format] = C::OutputFileFormat[:png]
similar_default(options_struct)
end

def similar_default(options_struct)
options_struct[:crop_x] = options_struct[:crop_y] = 0
options_struct[:crop_w] = options_struct[:crop_h] = 0
Expand Down
2 changes: 1 addition & 1 deletion lib/webp/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module WebP
VERSION = "0.2.0"
VERSION = "0.2.1"
end

0 comments on commit 88cd376

Please sign in to comment.