psd 3.3.3 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2bda3103c40e7402bbf6caa70f3c9087088f47a5
4
- data.tar.gz: e8bf4ebb6539390b2c64820392a35f01a3d3e730
3
+ metadata.gz: 3d022d5b521a64f3578c5755ba18d5bbc1f419ea
4
+ data.tar.gz: 3f72cd4899c112f55171eab1f96629e354d1eb9f
5
5
  SHA512:
6
- metadata.gz: 0c337cdc436e76d11c84ebee5e87070c101ebd49bb8f143bf25767de5aef5be26839874acb38ac00368a763de7830bdb9c640ecb6be9a92145f7920f1248e586
7
- data.tar.gz: 73b3e7a6072a3e6e3dcc3a1fb84373523d46553250a2dd343efedde77e34d9c307e4e383b857020a91b4a82e41d542adac7c76c891b6a4525c9fa1251f47fe24
6
+ metadata.gz: ed4a582c87fd81ee3a6a19d487cea8fa6e388740e16097e185268581af549d032c125b3d66fde8dfe52ec0af2f4d67c57bce0990030e3eb7b8f06b18b1b62c51
7
+ data.tar.gz: dce119bc89f527695fbd46229fbd82447d23722b60f19002afb0984bb10e3c7aee992ba301ad7f53cdd15ea4ad6277e47a2842ec21ca9bc17941e5ff4d561475
data/lib/psd/header.rb CHANGED
@@ -59,6 +59,10 @@ class PSD
59
59
  MODES[@mode]
60
60
  end
61
61
 
62
+ def big?
63
+ version == 2
64
+ end
65
+
62
66
  def rgb?
63
67
  mode == 3
64
68
  end
@@ -67,4 +71,4 @@ class PSD
67
71
  mode == 4
68
72
  end
69
73
  end
70
- end
74
+ end
@@ -7,7 +7,7 @@ class PSD
7
7
  def parse_byte_counts!
8
8
  byte_counts = []
9
9
  height.times do
10
- byte_counts << @file.read_short
10
+ byte_counts << (@header.big? ? @file.read_int : @file.read_short)
11
11
  end
12
12
 
13
13
  return byte_counts
@@ -21,4 +21,4 @@ class PSD
21
21
  end
22
22
  end
23
23
  end
24
- end
24
+ end
@@ -51,6 +51,8 @@ class PSD
51
51
  gradient_fill: GradientFill
52
52
  }.freeze
53
53
 
54
+ BIG_LAYER_INFO_KEYS = %w{ LMsk Lr16 Lr32 Layr Mt16 Mt32 Mtrn Alph FMsk lnk2 FEid FXid PxSD }
55
+
54
56
  attr_reader :adjustments
55
57
  alias :info :adjustments
56
58
 
@@ -60,6 +62,14 @@ class PSD
60
62
 
61
63
  private
62
64
 
65
+ def parse_additional_layer_info_length(key)
66
+ if @header.big? && BIG_LAYER_INFO_KEYS.include?(key)
67
+ Util.pad2 @file.read_longlong
68
+ else
69
+ Util.pad2 @file.read_int
70
+ end
71
+ end
72
+
63
73
  # This section is a bit tricky to parse because it represents all of the
64
74
  # extra data that describes this layer.
65
75
  def parse_layer_info
@@ -73,7 +83,7 @@ class PSD
73
83
  key = @file.read_string(4)
74
84
  @info_keys << key
75
85
 
76
- length = Util.pad2 @file.read_int
86
+ length = parse_additional_layer_info_length(key)
77
87
  pos = @file.tell
78
88
 
79
89
  key_parseable = false
@@ -21,7 +21,7 @@ class PSD
21
21
 
22
22
  @channels.times do
23
23
  channel_id = @file.read_short
24
- channel_length = @file.read_int
24
+ channel_length = @header.big? ? @file.read_longlong : @file.read_int
25
25
 
26
26
  @channels_info << {id: channel_id, length: channel_length}
27
27
  end
@@ -40,4 +40,4 @@ class PSD
40
40
  end
41
41
  end
42
42
  end
43
- end
43
+ end
@@ -18,13 +18,14 @@ class PSD
18
18
  # Allows us to skip this section because it starts with the length of the section
19
19
  # stored as an integer.
20
20
  def skip
21
- @file.seek @file.read_int, IO::SEEK_CUR
21
+ @file.seek parse_mask_size, IO::SEEK_CUR
22
22
  return self
23
23
  end
24
24
 
25
25
  # Parse this section, including all of the layers and folders.
26
26
  def parse
27
- mask_size = @file.read_int
27
+ mask_size = parse_mask_size
28
+
28
29
  start_position = @file.tell
29
30
  finish = start_position + mask_size
30
31
 
@@ -49,8 +50,20 @@ class PSD
49
50
 
50
51
  private
51
52
 
53
+ def parse_mask_size
54
+ @header.big? ? @file.read_longlong : @file.read_int
55
+ end
56
+
57
+ def parse_layer_info_size
58
+ Util.pad2(@header.big? ? @file.read_longlong : @file.read_int)
59
+ end
60
+
61
+ def channel_information_length
62
+ @header.big? ? 10 : 6
63
+ end
64
+
52
65
  def parse_layers
53
- layer_info_size = Util.pad2(@file.read_int)
66
+ layer_info_size = parse_layer_info_size
54
67
 
55
68
  if layer_info_size > 0
56
69
  layer_count = @file.read_short
@@ -60,7 +73,7 @@ class PSD
60
73
  @merged_alpha = true
61
74
  end
62
75
 
63
- if layer_count * (18 + 6 * @header.channels) > layer_info_size
76
+ if layer_count * (18 + channel_information_length * @header.channels) > layer_info_size
64
77
  PSD.logger.error "Unlikely number of layers parsed: #{layer_count}"
65
78
  end
66
79
 
@@ -21,6 +21,7 @@ class PSD
21
21
  def to_hash
22
22
  super.merge({
23
23
  type: :group,
24
+ open: section_divider ? section_divider.layer_type == 'open folder' : false,
24
25
  children: children.map(&:to_hash)
25
26
  })
26
27
  end
data/lib/psd/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class PSD
2
- VERSION = "3.3.3"
2
+ VERSION = "3.4.0"
3
3
  end
Binary file
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Photoshop Big parsing' do
4
+ before(:each) do
5
+ @psd = PSD.new('spec/files/example.psb')
6
+ end
7
+
8
+ it 'parses without error' do
9
+ @psd.parse!
10
+ expect(@psd).to be_parsed
11
+ end
12
+
13
+ describe 'Header' do
14
+ before(:each) do
15
+ @psd.parse!
16
+ end
17
+
18
+ it 'should contain data' do
19
+ expect(@psd.header).not_to be_nil
20
+ end
21
+
22
+ it 'should be the proper version' do
23
+ expect(@psd.header.version).to eq(2)
24
+ end
25
+ end
26
+
27
+ describe 'Layer Mask' do
28
+ before(:each) do
29
+ @psd.parse!
30
+ end
31
+
32
+ it 'contains data' do
33
+ expect(@psd.layer_mask).to_not be_nil
34
+ expect(@psd.layer_mask).to be_an_instance_of(PSD::LayerMask)
35
+ end
36
+
37
+ it 'contains layers' do
38
+ expect(@psd.layer_mask.layers.size).to be > 0
39
+ end
40
+ end
41
+
42
+ describe 'Layers' do
43
+ before(:each) do
44
+ @psd.parse!
45
+ end
46
+
47
+ it 'contains each layer' do
48
+ expect(@psd.layer_mask.layers.size).to eq(2)
49
+ expect(@psd.layers).to be @psd.layer_mask.layers
50
+ @psd.layers.each { |l| expect(l).to be_an_instance_of(PSD::Layer) }
51
+ end
52
+
53
+ it 'shows the proper layer names' do
54
+ expect(@psd.layers.map(&:name)).to match_array(['summer', 'haze'])
55
+ end
56
+ end
57
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: psd
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.3
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan LeFevre
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-06-04 00:00:00.000000000 Z
12
+ date: 2015-10-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -234,6 +234,7 @@ files:
234
234
  - spec/files/blendmodes.psd
235
235
  - spec/files/empty-layer-subgroups.psd
236
236
  - spec/files/empty-layer.psd
237
+ - spec/files/example.psb
237
238
  - spec/files/example.psd
238
239
  - spec/files/guides.psd
239
240
  - spec/files/locked.psd
@@ -249,6 +250,7 @@ files:
249
250
  - spec/lazy_execute_spec.rb
250
251
  - spec/locked_spec.rb
251
252
  - spec/parsing_spec.rb
253
+ - spec/psb_parsing_spec.rb
252
254
  - spec/psd_spec.rb
253
255
  - spec/slices_spec.rb
254
256
  - spec/spec_helper.rb
@@ -273,7 +275,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
273
275
  version: '0'
274
276
  requirements: []
275
277
  rubyforge_project:
276
- rubygems_version: 2.4.5
278
+ rubygems_version: 2.4.6
277
279
  signing_key:
278
280
  specification_version: 4
279
281
  summary: General purpose library for parsing Photoshop files
@@ -282,6 +284,7 @@ test_files:
282
284
  - spec/files/blendmodes.psd
283
285
  - spec/files/empty-layer-subgroups.psd
284
286
  - spec/files/empty-layer.psd
287
+ - spec/files/example.psb
285
288
  - spec/files/example.psd
286
289
  - spec/files/guides.psd
287
290
  - spec/files/locked.psd
@@ -297,6 +300,7 @@ test_files:
297
300
  - spec/lazy_execute_spec.rb
298
301
  - spec/locked_spec.rb
299
302
  - spec/parsing_spec.rb
303
+ - spec/psb_parsing_spec.rb
300
304
  - spec/psd_spec.rb
301
305
  - spec/slices_spec.rb
302
306
  - spec/spec_helper.rb