class Libis::Format::Converter::Jp2Converter

Public Class Methods

input_types() click to toggle source
# File lib/libis/format/converter/jp2_converter.rb, line 13
def self.input_types
  [:TIFF, :JPG, :PNG, :BMP, :GIF, :PDF]
end
new() click to toggle source
Calls superclass method Libis::Format::Converter::Base::new
# File lib/libis/format/converter/jp2_converter.rb, line 22
def initialize
  super
  @options = {
      color_xform: false,
      error_resilience: :ALL,
      lossless: true,
      progression_order: 'RLCP',
      tile_size: [1024, 1024],
      codeblock_size: [6, 6],
  }
end
output_types(format = nil) click to toggle source
# File lib/libis/format/converter/jp2_converter.rb, line 17
def self.output_types(format = nil)
  return [] unless input_types.include?(format) if format
  [:JP2]
end

Public Instance Methods

codeblock_size(width = 6, height = nil) click to toggle source
# File lib/libis/format/converter/jp2_converter.rb, line 59
def codeblock_size(width = 6, height = nil)
  height ||= width
  @options[:codeblock_size] = [height, width]
end
color_xform(flag = true) click to toggle source
# File lib/libis/format/converter/jp2_converter.rb, line 38
def color_xform(flag = true)
  @options[:color_xform] = flag
end
convert(source, target, format, opts = {}) click to toggle source
Calls superclass method Libis::Format::Converter::Base#convert
# File lib/libis/format/converter/jp2_converter.rb, line 64
def convert(source, target, format, opts = {})
  super

  FileUtils.mkpath(File.dirname(target))

  options = []

  @options.each do |key, value|
    case key
      when :color_xform
        options << '--set-output-j2k-color-xform' << (value ? 'YES' : 'NO')
      when :error_resilience
        options << '--set-output-j2k-error-resilience' << value.to_s
      when :lossless
        if value
          options << '--set-output-j2k-xform' << 'R53' << '5' << '--set-output-j2k-ratio' << '0'
        else
          options << '--set-output-j2k-xform' << 'I97' << '--set-output-j2k-psnr' << '46'
        end
      when :progression_order
        options << '--set-output-j2k-progression-order' << value.to_s
      when :tile_size
        options << '--set-output-j2k-tile-size' << value[0].to_s << value[1].to_s
      when :codeblock_size
        options << '--set-output-j2k-codeblock-size' << value[0].to_s << value[1].to_s
      else
        #do nothing
    end
  end


  Libis::Tools::Command.run(
      Libis::Format::Config[:j2k_cmd],
      '--input-file-name', source,
      '--set-output-type', 'JP2',
      *options,
      '--output-file-name', target,

  )

  target
end
error_resilience(value = :ALL) click to toggle source
# File lib/libis/format/converter/jp2_converter.rb, line 42
def error_resilience(value = :ALL)
  @options[:error_resilience] = value
end
j2kdriver(_) click to toggle source
# File lib/libis/format/converter/jp2_converter.rb, line 34
def j2kdriver(_)
  #force usage of this converter
end
lossless(value = true) click to toggle source
# File lib/libis/format/converter/jp2_converter.rb, line 46
def lossless(value = true)
  @options[:lossless] = value
end
progression_order(value = 'RLCP') click to toggle source
# File lib/libis/format/converter/jp2_converter.rb, line 50
def progression_order(value = 'RLCP')
  @options[:progression_order] = value
end
tile_size(width = 1024, height = nil) click to toggle source
# File lib/libis/format/converter/jp2_converter.rb, line 54
def tile_size(width = 1024, height = nil)
  height ||= width
  @options[:tile_size] = [width, height]
end