Class: PSD::Header

Inherits:
Object
  • Object
show all
Defined in:
lib/psd/header.rb

Constant Summary collapse

MODES =

All of the color modes are stored internally as a short from 0-15. This is a mapping of that value to a human-readable name.

[
  'Bitmap',
  'GrayScale',
  'IndexedColor',
  'RGBColor',
  'CMYKColor',
  'HSLColor',
  'HSBColor',
  'Multichannel',
  'Duotone',
  'LabColor',
  'Gray16',
  'RGB48',
  'Lab48',
  'CMYK64',
  'DeepMultichannel',
  'Duotone16'
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Header

Returns a new instance of Header.



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/psd/header.rb', line 29

def initialize(file)
  @file = file

  @sig = nil
  @version = nil
  @channels = nil
  @rows = nil
  @cols = nil
  @depth = nil
  @mode = nil
end

Instance Attribute Details

#channelsObject (readonly)

Returns the value of attribute channels.



3
4
5
# File 'lib/psd/header.rb', line 3

def channels
  @channels
end

#colsObject (readonly) Also known as: width

Returns the value of attribute cols.



3
4
5
# File 'lib/psd/header.rb', line 3

def cols
  @cols
end

#depthObject (readonly)

Returns the value of attribute depth.



3
4
5
# File 'lib/psd/header.rb', line 3

def depth
  @depth
end

#modeObject (readonly)

Returns the value of attribute mode.



3
4
5
# File 'lib/psd/header.rb', line 3

def mode
  @mode
end

#rowsObject (readonly) Also known as: height

Returns the value of attribute rows.



3
4
5
# File 'lib/psd/header.rb', line 3

def rows
  @rows
end

#sigObject (readonly)

Returns the value of attribute sig.



3
4
5
# File 'lib/psd/header.rb', line 3

def sig
  @sig
end

#versionObject (readonly)

Returns the value of attribute version.



3
4
5
# File 'lib/psd/header.rb', line 3

def version
  @version
end

Instance Method Details

#big?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/psd/header.rb', line 62

def big?
  version == 2
end

#cmyk?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/psd/header.rb', line 70

def cmyk?
  mode == 4
end

#mode_nameObject



58
59
60
# File 'lib/psd/header.rb', line 58

def mode_name
  MODES[@mode]
end

#parse!Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/psd/header.rb', line 41

def parse!
  @sig = @file.read_string(4)
  @version = @file.read_ushort

  # Reserved bytes, must be 0
  @file.seek 6, IO::SEEK_CUR

  @channels = @file.read_ushort
  @rows = @file.read_uint
  @cols = @file.read_uint
  @depth = @file.read_ushort
  @mode = @file.read_ushort

  color_data_len = @file.read_uint
  @file.seek color_data_len, IO::SEEK_CUR
end

#rgb?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/psd/header.rb', line 66

def rgb?
  mode == 3
end