Class: Quadtone::Profile
- Inherits:
-
Object
- Object
- Quadtone::Profile
- Defined in:
- lib/quadtone/profile.rb
Constant Summary collapse
- ProfilesDir =
BaseDir + 'profiles'
- ProfileName =
'profile.txt'
Instance Attribute Summary collapse
-
#characterization_curveset ⇒ Object
Returns the value of attribute characterization_curveset.
-
#default_ink_limit ⇒ Object
Returns the value of attribute default_ink_limit.
-
#gray_gamma ⇒ Object
Returns the value of attribute gray_gamma.
-
#gray_highlight ⇒ Object
Returns the value of attribute gray_highlight.
-
#gray_overlap ⇒ Object
Returns the value of attribute gray_overlap.
-
#gray_shadow ⇒ Object
Returns the value of attribute gray_shadow.
-
#ink_limits ⇒ Object
Returns the value of attribute ink_limits.
-
#ink_partitions ⇒ Object
Returns the value of attribute ink_partitions.
-
#inks ⇒ Object
Returns the value of attribute inks.
-
#linearization ⇒ Object
Returns the value of attribute linearization.
-
#linearization_curveset ⇒ Object
Returns the value of attribute linearization_curveset.
-
#medium ⇒ Object
Returns the value of attribute medium.
-
#printer ⇒ Object
Returns the value of attribute printer.
-
#printer_options ⇒ Object
Returns the value of attribute printer_options.
-
#test_curveset ⇒ Object
Returns the value of attribute test_curveset.
Class Method Summary collapse
Instance Method Summary collapse
- #check ⇒ Object
- #dir_path ⇒ Object
-
#initialize(params = {}) ⇒ Profile
constructor
A new instance of Profile.
- #ink_limit(ink) ⇒ Object
- #install ⇒ Object
- #load(name) ⇒ Object
- #name ⇒ Object
- #print_file(input_path, options = {}) ⇒ Object
- #qtr_profile_path ⇒ Object
- #quad_file_path ⇒ Object
- #save ⇒ Object
- #show ⇒ Object
- #to_html ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Profile
Returns a new instance of Profile.
34 35 36 37 38 39 40 41 42 43 44 |
# 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 |
Instance Attribute Details
#characterization_curveset ⇒ Object
Returns the value of attribute characterization_curveset.
17 18 19 |
# File 'lib/quadtone/profile.rb', line 17 def characterization_curveset @characterization_curveset end |
#default_ink_limit ⇒ Object
Returns the value of attribute default_ink_limit.
12 13 14 |
# File 'lib/quadtone/profile.rb', line 12 def default_ink_limit @default_ink_limit end |
#gray_gamma ⇒ Object
Returns the value of attribute gray_gamma.
16 17 18 |
# File 'lib/quadtone/profile.rb', line 16 def gray_gamma @gray_gamma end |
#gray_highlight ⇒ Object
Returns the value of attribute gray_highlight.
13 14 15 |
# File 'lib/quadtone/profile.rb', line 13 def gray_highlight @gray_highlight end |
#gray_overlap ⇒ Object
Returns the value of attribute gray_overlap.
15 16 17 |
# File 'lib/quadtone/profile.rb', line 15 def gray_overlap @gray_overlap end |
#gray_shadow ⇒ Object
Returns the value of attribute gray_shadow.
14 15 16 |
# File 'lib/quadtone/profile.rb', line 14 def gray_shadow @gray_shadow end |
#ink_limits ⇒ Object
Returns the value of attribute ink_limits.
10 11 12 |
# File 'lib/quadtone/profile.rb', line 10 def ink_limits @ink_limits end |
#ink_partitions ⇒ Object
Returns the value of attribute ink_partitions.
9 10 11 |
# File 'lib/quadtone/profile.rb', line 9 def ink_partitions @ink_partitions end |
#inks ⇒ Object
Returns the value of attribute inks.
8 9 10 |
# File 'lib/quadtone/profile.rb', line 8 def inks @inks end |
#linearization ⇒ Object
Returns the value of attribute linearization.
11 12 13 |
# File 'lib/quadtone/profile.rb', line 11 def linearization @linearization end |
#linearization_curveset ⇒ Object
Returns the value of attribute linearization_curveset.
18 19 20 |
# File 'lib/quadtone/profile.rb', line 18 def linearization_curveset @linearization_curveset end |
#medium ⇒ Object
Returns the value of attribute medium.
7 8 9 |
# File 'lib/quadtone/profile.rb', line 7 def medium @medium end |
#printer ⇒ Object
Returns the value of attribute printer.
5 6 7 |
# File 'lib/quadtone/profile.rb', line 5 def printer @printer end |
#printer_options ⇒ Object
Returns the value of attribute printer_options.
6 7 8 |
# File 'lib/quadtone/profile.rb', line 6 def @printer_options end |
#test_curveset ⇒ Object
Returns the value of attribute test_curveset.
19 20 21 |
# File 'lib/quadtone/profile.rb', line 19 def test_curveset @test_curveset end |
Class Method Details
.load(name) ⇒ Object
28 29 30 31 32 |
# File 'lib/quadtone/profile.rb', line 28 def self.load(name) profile = Profile.new profile.load(name) profile end |
.profile_names ⇒ Object
24 25 26 |
# File 'lib/quadtone/profile.rb', line 24 def self.profile_names Pathname.glob(ProfilesDir + '*').select { |p| p.directory? && p[0] != '.' }.map(&:basename) end |
Instance Method Details
#check ⇒ Object
211 212 213 |
# File 'lib/quadtone/profile.rb', line 211 def check #FIXME: check values end |
#dir_path ⇒ Object
132 133 134 |
# File 'lib/quadtone/profile.rb', line 132 def dir_path ProfilesDir + name end |
#ink_limit(ink) ⇒ Object
144 145 146 |
# File 'lib/quadtone/profile.rb', line 144 def ink_limit(ink) @ink_limits[ink] || @default_ink_limit end |
#install ⇒ Object
148 149 150 151 152 153 154 155 |
# File 'lib/quadtone/profile.rb', line 148 def install # filename needs to match name of profile for quadprofile to install it properly, # so temporarily make a symlink tmp_file = Pathname.new('/tmp') + "#{name}.txt" qtr_profile_path.symlink(tmp_file) system('/Library/Printers/QTR/bin/quadprofile', tmp_file) tmp_file.unlink end |
#load(name) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# 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 ⇒ Object
46 47 48 49 50 51 |
# 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 = {}) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/quadtone/profile.rb', line 157 def print_file(input_path, ={}) = HashStruct.new() = @printer_options.dup if . ..each do |key, value| [key.to_s] = value end end if .calibrate ['ColorModel'] = 'QTCAL' else ['ripCurve1'] = name end @printer.print_file(input_path, ) end |
#qtr_profile_path ⇒ Object
136 137 138 |
# File 'lib/quadtone/profile.rb', line 136 def qtr_profile_path dir_path + ProfileName end |
#quad_file_path ⇒ Object
140 141 142 |
# File 'lib/quadtone/profile.rb', line 140 def quad_file_path Pathname.new('/Library/Printers/QTR/quadtone') + @printer.name + "#{name}.quad" end |
#save ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# 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 ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/quadtone/profile.rb', line 173 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 ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/quadtone/profile.rb', line 199 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 |