psd 1.4.4 → 1.4.5

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: cfdf8466e7c4a858bf93d47ec823c26ef3a667fa
4
- data.tar.gz: bab2a4414c765c27a0d8de12b401067a2a894ba5
3
+ metadata.gz: 3c9491d68bacd47bd02b6ef1ebd95679de8f780d
4
+ data.tar.gz: 3890b2b104af1b45d7754005cf91736cfd88c2fa
5
5
  SHA512:
6
- metadata.gz: c80d095fbce20218530a13a3adcf29d9193a6dfe4e4a7b73bc3202bc04ddc3d1a80869d2c9f648ebca606f460647cc34e9d95f81a8bcdba0a044bd2070be8da0
7
- data.tar.gz: fabf5fcfceeab8e772228ac3088aa73c5d9382cae2d31f41b405cfd5c2542139f08bbeb1f5e20fe3f99a153b8e65071398315f7fb47b36bd2070e86ec4a0e065
6
+ metadata.gz: 03d6f9c5332ca2b8ac5e981743e3955f0b26d5cd8f6b3ec7643602cebd4d7f0ac766190e1ca7d4e6618c9784d33d319a7ab8b548919bd491079096290ca74166
7
+ data.tar.gz: e94c59785c2d9e6cac71e44e2f5a4efc8961e32da61f8382e36682af3a9ab6c58dba757a4411f383f87c6bc1a69cd9eaf9a5eedaa87ce4b2e6163b1d8e26a842
data/.travis.yml CHANGED
@@ -3,4 +3,4 @@ rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
5
  - jruby-19mode
6
- - rbx-19mode
6
+ # - rbx-19mode
data/lib/psd.rb CHANGED
@@ -120,7 +120,9 @@ class PSD
120
120
  # The image is the last section in the file, so we don't have to
121
121
  # bother with skipping over the bytes to read more data.
122
122
  image = Image.new(@file, @header)
123
- LazyExecute.new(image, @file).later(:parse)
123
+ LazyExecute.new(image, @file)
124
+ .later(:parse)
125
+ .ignore(:width, :height)
124
126
  )
125
127
  end
126
128
 
@@ -5,7 +5,10 @@ class PSD
5
5
 
6
6
  def parse_channel_image(header)
7
7
  image = PSD::ChannelImage.new(@file, header, self)
8
- @image = LazyExecute.new(image, @file).now(:skip).later(:parse)
8
+ @image = LazyExecute.new(image, @file)
9
+ .now(:skip)
10
+ .later(:parse)
11
+ .ignore(:width, :height)
9
12
  end
10
13
  end
11
14
  end
@@ -9,6 +9,7 @@ class PSD
9
9
  @loaded = false
10
10
  @load_method = nil
11
11
  @load_args = []
12
+ @passthru = []
12
13
 
13
14
  PSD.logger.debug "Marked #{@obj.class.name} at position #{@start_pos} for lazy execution"
14
15
  end
@@ -25,12 +26,17 @@ class PSD
25
26
  return self
26
27
  end
27
28
 
29
+ def ignore(*args)
30
+ @passthru += args
31
+ return self
32
+ end
33
+
28
34
  def loaded?
29
35
  @loaded
30
36
  end
31
37
 
32
38
  def method_missing(method, *args, &block)
33
- load! unless loaded?
39
+ load! if !loaded? && !@passthru.include?(method.to_sym)
34
40
  @obj.send(method, *args, &block)
35
41
  end
36
42
 
data/lib/psd/mask.rb CHANGED
@@ -1,45 +1,74 @@
1
1
  class PSD
2
- # Represents the mask for a single layer
3
- class Mask < BinData::Record
4
- endian :big
2
+ class Mask
3
+ attr_reader :size, :top, :left, :bottom, :right, :default_color
5
4
 
6
- int32 :mask_size
5
+ def self.read(file)
6
+ mask = Mask.new(file)
7
+ mask.parse
7
8
 
8
- int32 :top, onlyif: :has_data?
9
- int32 :left, onlyif: :has_data?
10
- int32 :bottom, onlyif: :has_data?
11
- int32 :right, onlyif: :has_data?
12
- int8 :default_color, onlyif: :has_data?
13
- bit8 :flags, onlyif: :has_data?
9
+ mask
10
+ end
11
+
12
+ def initialize(file)
13
+ @file = file
14
+ @top = 0
15
+ @left = 0
16
+ @bottom = 0
17
+ @right = 0
18
+ end
19
+
20
+ def parse
21
+ @size = @file.read_int
22
+ return if @size == 0
23
+
24
+ @mask_end = @file.tell + @size
14
25
 
15
- skip length: 2, onlyif: lambda { mask_size == 20 }
16
- skip length: 18, onlyif: lambda { mask_size > 0 && mask_size != 20}
26
+ @top = @file.read_int
27
+ @left = @file.read_int
28
+ @bottom = @file.read_int
29
+ @right = @file.read_int
17
30
 
18
- # Is there a mask defined?
19
- def has_data?
20
- mask_size > 0
31
+ @default_color = @file.read_byte
32
+ @flags = @file.read_byte
33
+
34
+ @file.seek @mask_end # Useless info/padding
21
35
  end
22
36
 
23
- # Width of the mask
24
37
  def width
25
38
  right - left
26
39
  end
27
40
 
28
- # Height of the mask
29
41
  def height
30
42
  bottom - top
31
43
  end
32
44
 
33
45
  def relative
34
- flags & 0x01
46
+ (@flags & 0x01) > 0
35
47
  end
36
48
 
37
49
  def disabled
38
- (flags & (0x01 << 1)) > 0
50
+ (@flags & (0x01 << 1)) > 0
39
51
  end
40
52
 
41
53
  def invert
42
- (flags & (0x01 << 2)) > 0
54
+ (@flags & (0x01 << 2)) > 0
55
+ end
56
+
57
+ def to_hash
58
+ return {} if @size == 0
59
+
60
+ {
61
+ top: top,
62
+ left: left,
63
+ bottom: bottom,
64
+ right: right,
65
+ width: width,
66
+ height: height,
67
+ default_color: default_color,
68
+ relative: relative,
69
+ disabled: disabled,
70
+ invert: invert
71
+ }
43
72
  end
44
73
  end
45
74
  end
@@ -59,7 +59,7 @@ class PSD::Node
59
59
  text: @layer.text,
60
60
  ref_x: @layer.reference_point.x,
61
61
  ref_y: @layer.reference_point.y,
62
- mask: @layer.mask.snapshot,
62
+ mask: @layer.mask.to_hash,
63
63
  image: {
64
64
  width: @layer.image.width,
65
65
  height: @layer.image.height,
data/lib/psd/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class PSD
2
- VERSION = "1.4.4"
2
+ VERSION = "1.4.5"
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: 1.4.4
4
+ version: 1.4.5
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: 2013-11-25 00:00:00.000000000 Z
12
+ date: 2013-11-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake