psd 3.1.3 → 3.1.4

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: f50b617c54533215a7298c60bd67cf41a822b9b4
4
- data.tar.gz: 5e460352673f2a562d1539ef354297a776431beb
3
+ metadata.gz: eb7572d17b8e7e05b8b8b6843c83a22762494919
4
+ data.tar.gz: 6a818b7de688fb558af6beebebf08c09c302b2df
5
5
  SHA512:
6
- metadata.gz: 48fb4c174e1faace5c98f63f5a5ed584a4a459c553d7c284efa1e15b22bfdbc5e28bfd93dac16d4e9a1f7c47dba1dc3f40e05d9c514e1045ccd90590d38f39d3
7
- data.tar.gz: 79ebfea952eb57031c6cc0d57e803728c20cb107597a2df578261dcf677708d5a998701039ef9a4032aad374a556ce33a2dc816dbf64ab17c9ec5756cfa96f70
6
+ metadata.gz: 0d91325e567d009ced2d66206c893ec04685ce4c10ed59353f6aba0487bf8934e32af53937f81e1aa4559a92672fa1948059f69fdb57a33194f0cdaeb2320695
7
+ data.tar.gz: 4ed05ad62147b7b47ca313288edfcce737e7da0dc5470f25b01d9b539494f1842c6f7d51ac1b4d4431c4d45eebf0e2353a6b79a97eb02017c6134c10d24169b8
@@ -23,7 +23,8 @@ class PSD
23
23
  vector_mask: VectorMask,
24
24
  vector_origination: VectorOrigination,
25
25
  vector_stroke: VectorStroke,
26
- vector_stroke_content: VectorStrokeContent
26
+ vector_stroke_content: VectorStrokeContent,
27
+ gradient_fill: GradientFill
27
28
  }.freeze
28
29
 
29
30
  attr_reader :adjustments
@@ -59,7 +60,7 @@ class PSD
59
60
 
60
61
  i = info.new(self, length)
61
62
  @adjustments[name] = LazyExecute.new(i, @file).now(:skip).later(:parse)
62
-
63
+
63
64
  key_parseable = true and break
64
65
  end
65
66
 
@@ -73,4 +74,4 @@ class PSD
73
74
  end
74
75
  end
75
76
  end
76
- end
77
+ end
@@ -0,0 +1,14 @@
1
+ require 'psd/layer_info'
2
+
3
+ class PSD
4
+ class GradientFill < LayerInfo
5
+ def self.should_parse?(key)
6
+ key == 'GdFl'
7
+ end
8
+
9
+ def parse
10
+ @file.seek 4, IO::SEEK_CUR
11
+ @data = Descriptor.new(@file).parse
12
+ end
13
+ end
14
+ end
@@ -12,7 +12,7 @@ class PSD
12
12
 
13
13
  @layers = []
14
14
  @merged_alpha = false
15
- @global_mask = nil
15
+ @global_mask = nil
16
16
  end
17
17
 
18
18
  # Allows us to skip this section because it starts with the length of the section
@@ -25,10 +25,29 @@ class PSD
25
25
  # Parse this section, including all of the layers and folders.
26
26
  def parse
27
27
  mask_size = @file.read_int
28
- finish = @file.tell + mask_size
28
+ start_position = @file.tell
29
+ finish = start_position + mask_size
29
30
 
30
31
  return self if mask_size <= 0
31
32
 
33
+ parse_layers
34
+ parse_global_mask
35
+
36
+ consumed_bytes = @file.tell - start_position
37
+ parse_layer_tagged_blocks(mask_size - consumed_bytes)
38
+
39
+ # Layers are parsed in reverse order
40
+ layers.reverse!
41
+
42
+ # Ensure we're at the end of this section
43
+ @file.seek finish
44
+
45
+ self
46
+ end
47
+
48
+ private
49
+
50
+ def parse_layers
32
51
  layer_info_size = Util.pad2(@file.read_int)
33
52
 
34
53
  if layer_info_size > 0
@@ -52,59 +71,43 @@ class PSD
52
71
  layer.parse_channel_image(@header)
53
72
  end
54
73
  end
55
-
56
- # Layers are parsed in reverse order
57
- layers.reverse!
58
- group_layers
59
-
60
- parse_global_mask
61
-
62
- # Ensure we're at the end of this section
63
- @file.seek finish
64
-
65
- return self
66
74
  end
67
75
 
68
- # Export the mask and all the children layers to a file.
69
- def export(outfile)
70
- if @layers.size == 0
71
- # No data, just read whatever's here.
72
- return outfile.write @file.read(@section_end[:all] - start_of_section)
76
+ def parse_layer_tagged_blocks(remaining_length)
77
+ end_pos = @file.tell + remaining_length
78
+
79
+ while @file.tell < end_pos
80
+ res = parse_additional_layer_info_block
81
+ break unless res
73
82
  end
83
+ end
74
84
 
75
- # Read the initial mask data since it won't change
76
- outfile.write @file.read(@layer_section_start - @file.tell)
85
+ def parse_additional_layer_info_block
86
+ sig = @file.read_string(4)
77
87
 
78
- @layers.reverse.each do |layer|
79
- layer.export(outfile)
88
+ unless %w(8BIM 8B64).include?(sig)
89
+ @file.seek(-4, IO::SEEK_CUR)
90
+ return false
80
91
  end
81
92
 
82
- outfile.write @file.read(end_of_section - @file.tell)
83
- end
84
-
85
- private
93
+ key = @file.read_string(4)
86
94
 
87
- def group_layers
88
- group_layer = nil
89
- layers.each do |layer|
90
- if layer.folder?
91
- group_layer = layer
92
- elsif layer.folder_end?
93
- group_layer = nil
94
- else
95
- layer.group_layer = layer
96
- end
95
+ if %w(Lr16 Lr32 Mt16).include?(key)
96
+ parse_layers
97
+ return true
97
98
  end
99
+
100
+ false
98
101
  end
99
102
 
100
103
  def parse_global_mask
101
104
  length = @file.read_int
102
-
105
+
103
106
  PSD.logger.debug "Global Mask: length = #{length}"
104
107
  return if length <= 0
105
108
 
106
109
  mask_end = @file.tell + length
107
-
110
+
108
111
  @global_mask = {}
109
112
  @global_mask[:overlay_color_space] = @file.read_short
110
113
  @global_mask[:color_components] = 4.times.map { |i| @file.read_short >> 8 }
@@ -119,4 +122,4 @@ class PSD
119
122
  @file.seek mask_end
120
123
  end
121
124
  end
122
- end
125
+ end
@@ -6,7 +6,7 @@
6
6
  end
7
7
 
8
8
  def to_png
9
- @png ||= renderer.to_png
9
+ @png ||= renderer(render_hidden: self.layer?).to_png
10
10
  end
11
11
 
12
12
  def save_as_png(output)
@@ -4,10 +4,6 @@ class PSD
4
4
  module Node
5
5
  # Represents the root node of a Photoshop document
6
6
  class Root < PSD::Node::Base
7
- include Ancestry
8
- include Search
9
- include BuildPreview
10
-
11
7
  attr_accessor :children
12
8
  attr_reader :psd
13
9
 
data/lib/psd/renderer.rb CHANGED
@@ -7,6 +7,7 @@ class PSD
7
7
  def initialize(node, opts = {})
8
8
  @root_node = node
9
9
  @opts = opts
10
+ @render_hidden = opts.delete(:render_hidden)
10
11
 
11
12
  # Our canvas always starts as the full document size because
12
13
  # all measurements are relative to this size. We can later crop
@@ -35,8 +36,10 @@ class PSD
35
36
  def execute_pipeline
36
37
  PSD.logger.debug "Executing pipeline on #{active_node.debug_name}"
37
38
  children.reverse.each do |child|
38
- # We skip over hidden nodes.
39
- next unless child.visible?
39
+ # We skip over hidden nodes unless explicitly set otherwise.
40
+ # If rendering a single PSD::Node::Layer, this is automatically
41
+ # set so that hidden layers will render.
42
+ next if !@render_hidden && !child.visible?
40
43
 
41
44
  if child.group?
42
45
  push_node(child)
data/lib/psd/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class PSD
2
- VERSION = "3.1.3"
2
+ VERSION = "3.1.4"
3
3
  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.1.3
4
+ version: 3.1.4
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: 2014-04-23 00:00:00.000000000 Z
12
+ date: 2014-05-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -186,6 +186,7 @@ files:
186
186
  - lib/psd/layer_info/blend_clipping_elements.rb
187
187
  - lib/psd/layer_info/blend_interior_elements.rb
188
188
  - lib/psd/layer_info/fill_opacity.rb
189
+ - lib/psd/layer_info/gradient_fill.rb
189
190
  - lib/psd/layer_info/layer_group.rb
190
191
  - lib/psd/layer_info/layer_id.rb
191
192
  - lib/psd/layer_info/layer_name_source.rb
@@ -282,7 +283,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
282
283
  version: '0'
283
284
  requirements: []
284
285
  rubyforge_project:
285
- rubygems_version: 2.2.1
286
+ rubygems_version: 2.2.2
286
287
  signing_key:
287
288
  specification_version: 4
288
289
  summary: General purpose library for parsing Photoshop files