Class: WebP::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/webp/options.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Options

Returns a new instance of Options.



4
5
6
# File 'lib/webp/options.rb', line 4

def initialize(options)
  @user_options = options
end

Instance Method Details

#decode_pointerObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/webp/options.rb', line 26

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, :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_h, :resize_w, :resize_h].each do |key|
      options_struct[key] = @user_options[key] if @user_options[key]
  end
  options_pointer
end

#encode_pointerObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/webp/options.rb', line 8

def encode_pointer
  options_pointer = FFI::MemoryPointer.new :char, C::FfiWebpEncodeConfig.size, false
  options_struct = C::FfiWebpEncodeConfig.new options_pointer
  [: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,
    :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,
    :crop_h, :resize_w, :resize_h].each do |key|
      options_struct[key] = @user_options[key] if @user_options[key]
  end
  options_pointer
end