class Quadtone::QuadFile

Constants

ChannelAliases

Attributes

curve_set[RW]

Public Class Methods

new(profile) click to toggle source
# File lib/quadtone/quad_file.rb, line 17
def initialize(profile)
  @profile = profile
  @curve_set = CurveSet.new(channels: [], profile: @profile, type: :separation)
  load(@profile.quad_file_path)
end

Public Instance Methods

load(quad_file) click to toggle source

Read QTR quad (curve) file

# File lib/quadtone/quad_file.rb, line 25
def load(quad_file)
  ;;warn "reading #{quad_file}"
  lines = Path.new(quad_file).open.readlines.map { |line| line.chomp.force_encoding('ISO-8859-1') }
  # process header
  channels = parse_channel_list(lines.shift)
  channels.each do |channel|
    samples = (0..255).to_a.map do |input|
      lines.shift while lines.first =~ /^#/
      line = lines.shift
      line =~ /^(\d+)$/ or raise "Unexpected value: #{line.inspect}"
      output = $1.to_i
      Sample.new(input: Color::Gray.new(k: 100 * (input / 255.0)), output: Color::Gray.new(k: 100 * (output / 65535.0)))
    end
    if @profile.inks.include?(channel)
      @curve_set.curves << Curve.new(channel: channel, samples: samples)
    end
  end
end
parse_channel_list(line) click to toggle source
# File lib/quadtone/quad_file.rb, line 44
def parse_channel_list(line)
  # "## QuadToneRIP K,C,M,Y,LC,LM"
  # "## QuadToneRIP KCMY"
  line =~ /^##\s+QuadToneRIP\s+(.*)$/ or raise "Unexpected header line: #{line.inspect}"
  channel_list = $1
  case channel_list
  when /,/
    channel_list.split(',')
  else
    channel_list.chars.map { |c| ChannelAliases[c] }
  end.map { |c| c.downcase.to_sym }
end