Module: Bpg::Encoder

Defined in:
lib/bpg/encoder.rb

Class Method Summary collapse

Class Method Details

.encode(input_file, params = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/bpg/encoder.rb', line 19

def self.encode(input_file, params = {})
  tmp_output_file = Tempfile.new('bpg')

  encode_to_file(input_file, tmp_output_file.path, params)

  tmp_output_file.rewind
  data = tmp_output_file.read
  tmp_output_file.close
  tmp_output_file.unlink

  data
end

.encode_to_file(input_file, output_file, params = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/bpg/encoder.rb', line 6

def self.encode_to_file(input_file, output_file, params = {})
  params  = Bpg::Config::CONFIG.merge(params)
  options = ''

  options += "-q #{params[:quantizer]} "
  options += "-f #{params[:chroma]} "
  options += "-c #{params[:color_space]} "
  options += "-b #{params[:bit_depth]} "
  options += '-lossless' if params[:lossless]

  `#{params[:bpgenc]} -o #{output_file} #{options} #{input_file}`
end