class Quadtone::Profile
Constants
- ProfileName
- ProfilesDir
Attributes
characterization_curveset[RW]
default_ink_limit[RW]
gray_gamma[RW]
gray_highlight[RW]
gray_overlap[RW]
gray_shadow[RW]
ink_limits[RW]
ink_partitions[RW]
inks[RW]
linearization[RW]
linearization_curveset[RW]
medium[RW]
printer[RW]
printer_options[RW]
test_curveset[RW]
Public Class Methods
load(name)
click to toggle source
# File lib/quadtone/profile.rb, line 28 def self.load(name) profile = Profile.new profile.load(name) profile end
new(params={})
click to toggle source
# File lib/quadtone/profile.rb, line 34 def initialize(params={}) @printer_options = nil @default_ink_limit = 1.0 @ink_limits = {} @ink_partitions = {} @gray_highlight = 0.06 @gray_shadow = 0.06 @gray_overlap = 0.10 @gray_gamma = 1.0 params.each { |key, value| send("#{key}=", value) } end
profile_names()
click to toggle source
# File lib/quadtone/profile.rb, line 24 def self.profile_names ProfilesDir.children.select { |p| p.directory? && p.basename.to_s[0] != '.' }.map(&:basename).map(&:to_s) end
Public Instance Methods
check()
click to toggle source
# File lib/quadtone/profile.rb, line 215 def check #FIXME: check values end
dir_path()
click to toggle source
# File lib/quadtone/profile.rb, line 132 def dir_path ProfilesDir / name end
html_path()
click to toggle source
# File lib/quadtone/profile.rb, line 144 def html_path dir_path / 'profile.html' end
ink_limit(ink)
click to toggle source
# File lib/quadtone/profile.rb, line 148 def ink_limit(ink) @ink_limits[ink] || @default_ink_limit end
install()
click to toggle source
# File lib/quadtone/profile.rb, line 152 def install # filename needs to match name of profile for quadprofile to install it properly, # so temporarily make a symlink tmp_file = Path.new('/tmp') / "#{name}.txt" qtr_profile_path.symlink(tmp_file.to_s) system('/Library/Printers/QTR/bin/quadprofile', tmp_file.to_s) tmp_file.unlink end
load(name)
click to toggle source
# File lib/quadtone/profile.rb, line 53 def load(name) inks_by_num = [] (ProfilesDir / name / ProfileName).readlines.each do |line| line.chomp! line.sub!(/#.*/, '') line.strip! next if line.empty? key, value = line.split('=', 2) case key when 'PRINTER' @printer = Printer.new(value) when 'PRINTER_OPTIONS' @printer_options = Hash[ value.split(',').map { |o| o.split('=') } ] when 'MEDIUM' @medium = value when 'GRAPH_CURVE' # ignore when 'N_OF_INKS' # ignore when 'INKS' @inks = value.split(',').map(&:downcase).map(&:to_sym) when 'DEFAULT_INK_LIMIT' @default_ink_limit = value.to_f / 100 when /^LIMIT_(.+)$/ @ink_limits[$1.downcase.to_sym] = value.to_f / 100 when 'N_OF_GRAY_PARTS' # ignore when /^GRAY_INK_(\d+)$/ i = $1.to_i - 1 inks_by_num[i] = value.downcase.to_sym when /^GRAY_VAL_(\d+)$/ i = $1.to_i - 1 ink = inks_by_num[i] @ink_partitions[ink] = value.to_f / 100 when 'GRAY_HIGHLIGHT' @gray_highlight = value.to_f / 100 when 'GRAY_SHADOW' @gray_shadow = value.to_f / 100 when 'GRAY_OVERLAP' @gray_overlap = value.to_f / 100 when 'GRAY_GAMMA' @gray_gamma = value.to_f when 'LINEARIZE' @linearization = value.gsub('"', '').split(/\s+/).map { |v| Color::Lab.new([v.to_f]) } else warn "Unknown key in QTR profile: #{key.inspect}" end end @characterization_curveset = CurveSet.new(channels: @inks, profile: self, type: :characterization) @linearization_curveset = CurveSet.new(channels: [:k], profile: self, type: :linearization) end
name()
click to toggle source
# File lib/quadtone/profile.rb, line 46 def name [ @printer.name.gsub(/[^-A-Z0-9]/i, ''), @medium.gsub(/[^-A-Z0-9]/i, ''), ].flatten.join('-') end
print_file(input_path, options={})
click to toggle source
# File lib/quadtone/profile.rb, line 161 def print_file(input_path, options={}) options = HashStruct.new(options) printer_options = @printer_options.dup if options.printer_options options.printer_options.each do |key, value| printer_options[key.to_s] = value end end if options.calibrate printer_options['ColorModel'] = 'QTCAL' else printer_options['ripCurve1'] = name end @printer.print_file(input_path, printer_options) end
qtr_profile_path()
click to toggle source
# File lib/quadtone/profile.rb, line 136 def qtr_profile_path dir_path / ProfileName end
quad_file_path()
click to toggle source
# File lib/quadtone/profile.rb, line 140 def quad_file_path Path.new('/Library/Printers/QTR/quadtone') / @printer.name / "#{name}.quad" end
save()
click to toggle source
# File lib/quadtone/profile.rb, line 105 def save qtr_profile_path.dirname.mkpath qtr_profile_path.open('w') do |io| io.puts "PRINTER=#{@printer.name}" io.puts "PRINTER_OPTIONS=#{@printer_options.map { |k, v| [k, v].join('=') }.join(',')}" if @printer_options io.puts "MEDIUM=#{@medium}" io.puts "GRAPH_CURVE=YES" io.puts "INKS=#{@inks.join(',')}" io.puts "N_OF_INKS=#{@inks.length}" io.puts "DEFAULT_INK_LIMIT=#{@default_ink_limit * 100}" @ink_limits.each do |ink, limit| io.puts "LIMIT_#{ink.upcase}=#{limit * 100}" end io.puts "N_OF_GRAY_PARTS=#{@ink_partitions.length}" @ink_partitions.each_with_index do |partition, i| ink, value = *partition io.puts "GRAY_INK_#{i+1}=#{ink.upcase}" io.puts "GRAY_VAL_#{i+1}=#{value * 100}" end io.puts "GRAY_HIGHLIGHT=#{@gray_highlight * 100}" io.puts "GRAY_SHADOW=#{@gray_shadow * 100}" io.puts "GRAY_OVERLAP=#{@gray_overlap * 100}" io.puts "GRAY_GAMMA=#{@gray_gamma}" io.puts "LINEARIZE=\"#{@linearization.map(&:l).join(' ')}\"" if @linearization end end
show()
click to toggle source
# File lib/quadtone/profile.rb, line 177 def show puts "Profile: #{name}" puts "Printer: #{@printer.name}" puts "Printer options:" @printer_options.each do |key, value| puts "\t" + "#{key}: #{value}" end puts "Medium: #{@medium}" puts "Inks: #{@inks.join(', ')}" puts "Default ink limit: #{@default_ink_limit}" puts "Ink limits:" @ink_limits.each do |ink, limit| puts "\t" + "#{ink.upcase}: #{limit}" end puts "Gray settings:" puts "\t" + "Highlight: #{@gray_highlight}" puts "\t" + "Shadow: #{@gray_shadow}" puts "\t" + "Overlap: #{@gray_overlap}" puts "Gray gamma: #{@gray_gamma}" puts "Ink partitions:" @ink_partitions.each do |ink, value| puts "\t" + "#{ink.upcase}: #{value}" end puts "Linearization: #{@linearization.join(', ')}" if @linearization end
to_html()
click to toggle source
# File lib/quadtone/profile.rb, line 203 def to_html html = Builder::XmlMarkup.new(indent: 2) html.html do html.head do end html.body do html.h1("Profile: #{name}") end end html.target! end