Class: Pdfrb::Color::ICCProfile

Inherits:
Object
  • Object
show all
Defined in:
lib/pdfrb/color/icc_profile.rb

Overview

ICC profile stream model. An ICCBased color space is a [/ICCBased ] array where the stream carries the raw ICC profile bytes and the dictionary declares /N (number of components), /Alternate (fallback space), and /Range.

This class parses the ICC header to extract metadata (version, device class, color space, component count) and builds the PDF stream dictionary.

ICC spec: ISO 15076-1 / ICC.1:2010. PDF integration: ISO 32000-2 ยง8.6.5.5.

Constant Summary collapse

HEADER_SIZE =
128
SIGNATURE_OFFSET =
36

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_data, alternate: nil) ⇒ ICCProfile

Returns a new instance of ICCProfile.



22
23
24
25
26
# File 'lib/pdfrb/color/icc_profile.rb', line 22

def initialize(raw_data, alternate: nil)
  @raw_data = raw_data.b
  parse_header
  @alternate = alternate || derive_alternate
end

Instance Attribute Details

#alternateObject (readonly)

Returns the value of attribute alternate.



19
20
21
# File 'lib/pdfrb/color/icc_profile.rb', line 19

def alternate
  @alternate
end

#color_spaceObject (readonly)

Returns the value of attribute color_space.



19
20
21
# File 'lib/pdfrb/color/icc_profile.rb', line 19

def color_space
  @color_space
end

#component_countObject (readonly)

Returns the value of attribute component_count.



19
20
21
# File 'lib/pdfrb/color/icc_profile.rb', line 19

def component_count
  @component_count
end

#device_classObject (readonly)

Returns the value of attribute device_class.



19
20
21
# File 'lib/pdfrb/color/icc_profile.rb', line 19

def device_class
  @device_class
end

#raw_dataObject (readonly)

Returns the value of attribute raw_data.



19
20
21
# File 'lib/pdfrb/color/icc_profile.rb', line 19

def raw_data
  @raw_data
end

#versionObject (readonly)

Returns the value of attribute version.



19
20
21
# File 'lib/pdfrb/color/icc_profile.rb', line 19

def version
  @version
end

Class Method Details

.read(path) ⇒ Object



28
29
30
# File 'lib/pdfrb/color/icc_profile.rb', line 28

def self.read(path)
  new(File.binread(path))
end

Instance Method Details

#pdf_color_space_arrayObject



32
33
34
# File 'lib/pdfrb/color/icc_profile.rb', line 32

def pdf_color_space_array
  [:ICCBased, :__icc_stream_ref__]
end

#stream_dictionary_fieldsObject



36
37
38
39
40
41
# File 'lib/pdfrb/color/icc_profile.rb', line 36

def stream_dictionary_fields
  {
    N: @component_count,
    Alternate: @alternate,
  }.freeze
end

#valid?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/pdfrb/color/icc_profile.rb', line 43

def valid?
  @raw_data.bytesize >= HEADER_SIZE && signature_valid?
end