psd 1.4.2 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f9c53ce033fdba16caf70bf522d538ced6658f4
4
- data.tar.gz: bd3827fcd93cf3a44c517b8e76504e4b7302fad0
3
+ metadata.gz: e989ef2453ff6c7b5e1c5e78590921ba53c679d6
4
+ data.tar.gz: 7b4dadc4460ad50512119776d4ca3e97f30782a9
5
5
  SHA512:
6
- metadata.gz: f5e146a36e2630d1833ab163dee71137cc469c46f2fbe6c766f2b170a182e33974cb911208c0fb7b9e9ffac62a97c764c07b6e9ba3eb77a5ab9459f72b01d395
7
- data.tar.gz: 04f8f7140acfc9c972432723721603bc4650572e526bae647da386308b49a6fa734447149a945a6f1bbbd90e3428365cd280f4dbfd389d7c140784fc7e8a1b0e
6
+ metadata.gz: 219a65e3412907b5672831101ad86bc7ba900dee53f571261cae77a39137589028c170950f52b85e477b039aa596840abb35a6ce0506d515e7866162390eec56
7
+ data.tar.gz: 5b8436682d202ceaa47e75dccdd59470f868231473cb91c8212aefb35ed2024dfa709adddd8b650b17d8411561dfb12dadb1afeb63445aefecc64fdaea1b9780
@@ -36,7 +36,12 @@ class PSD::Image
36
36
  i = 0
37
37
  @layer.height.times do |y|
38
38
  @layer.width.times do |x|
39
- png[x + @layer.left, y + @layer.top] = @pixel_data[i]
39
+ offset_x = x + @layer.left
40
+ offset_y = y + @layer.top
41
+
42
+ i +=1 and next if offset_x < 0 || offset_y < 0 || offset_x >= png.width || offset_y >= png.height
43
+
44
+ png[offset_x, offset_y] = @pixel_data[i]
40
45
  i += 1
41
46
  end
42
47
  end
@@ -48,15 +53,22 @@ class PSD::Image
48
53
  offset_x = @layer.mask.left + x
49
54
  offset_y = @layer.mask.top + y
50
55
 
51
- color = ChunkyPNG::Color.to_truecolor_alpha_bytes(png.get_pixel(offset_x, offset_y))
56
+ i += 1 and next if offset_x < 0 || offset_y < 0 || offset_x >= png.width || offset_y >= png.height
57
+
58
+ color = ChunkyPNG::Color.to_truecolor_alpha_bytes(png[offset_x, offset_y])
52
59
  color[3] = color[3] * @mask_data[i] / 255
53
60
 
54
- png.set_pixel(offset_x, offset_y, ChunkyPNG::Color.rgba(*color))
61
+ png[offset_x, offset_y] = ChunkyPNG::Color.rgba(*color)
55
62
  i += 1
56
63
  end
57
64
  end
58
65
 
59
- png.crop!(@layer.left, @layer.top, @layer.width.to_i, @layer.height.to_i)
66
+ crop_left = PSD::Util.clamp(@layer.left, 0, png.width)
67
+ crop_top = PSD::Util.clamp(@layer.top, 0, png.height)
68
+ crop_width = PSD::Util.clamp(@layer.width.to_i, 0, png.width - crop_left)
69
+ crop_height = PSD::Util.clamp(@layer.height.to_i, 0, png.height - crop_top)
70
+
71
+ png.crop!(crop_left, crop_top, crop_width, crop_height)
60
72
  end
61
73
 
62
74
  def mask_to_png
@@ -9,11 +9,11 @@ class PSD
9
9
  grey = @channel_data[i]
10
10
  alpha = @channel_data[@channel_length + i]
11
11
 
12
- @pixel_data.push ChunkyPNG::Color.greyscale_alpha(grey, alpha)
12
+ @pixel_data.push ChunkyPNG::Color.grayscale_alpha(grey, alpha)
13
13
  end
14
14
  else
15
15
  (0...@num_pixels).step(pixel_step) do |i|
16
- @pixel_data.push ChunkyPNG::Color.greyscale(@channel_data[i])
16
+ @pixel_data.push ChunkyPNG::Color.grayscale(@channel_data[i])
17
17
  end
18
18
  end
19
19
  end
@@ -10,7 +10,6 @@ class PSD
10
10
  (0...@num_pixels).step(pixel_step) do |i|
11
11
  r = g = b = 0
12
12
  a = 255
13
- mask = nil
14
13
 
15
14
  @channels_info.each_with_index do |chan, index|
16
15
  next if chan[:id] == -2
@@ -18,7 +17,7 @@ class PSD
18
17
  val = @channel_data[i + (@channel_length * index)]
19
18
 
20
19
  case chan[:id]
21
- when -1 then a = (val * opacity).to_i
20
+ when -1 then a = val
22
21
  when 0 then r = val
23
22
  when 1 then g = val
24
23
  when 2 then b = val
@@ -22,7 +22,13 @@ class PSD
22
22
  compose! c, png, c.build_png, 0, 0
23
23
  end
24
24
  else
25
- compose! c, png, c.image.to_png_with_mask, c.left.to_i, c.top.to_i
25
+ compose!(
26
+ c,
27
+ png,
28
+ c.image.to_png_with_mask,
29
+ PSD::Util.clamp(c.left.to_i, 0, png.width),
30
+ PSD::Util.clamp(c.top.to_i, 0, png.height)
31
+ )
26
32
  end
27
33
  end
28
34
 
@@ -37,7 +43,7 @@ class PSD
37
43
  end
38
44
 
39
45
  # Modified from ChunkyPNG::Canvas#compose! in order to support various blend modes.
40
- def compose!(layer, base, other, offset_x = 0, offset_y = 0)
46
+ def compose!(layer, base, other, offset_x, offset_y)
41
47
  blending_mode = layer.blending_mode.gsub(/ /, '_')
42
48
  PSD.logger.warn("Blend mode #{blending_mode} is not implemented") unless Compose.respond_to?(blending_mode)
43
49
  PSD.logger.debug("Blending #{layer.name} with #{blending_mode} blend mode")
@@ -45,6 +51,10 @@ class PSD
45
51
  LayerStyles.new(layer, other).apply!
46
52
  other = ClippingMask.new(layer, other).apply
47
53
 
54
+ blend_pixels!(blending_mode, layer, base, other, offset_x, offset_y)
55
+ end
56
+
57
+ def blend_pixels!(blending_mode, layer, base, other, offset_x, offset_y)
48
58
  other.height.times do |y|
49
59
  other.width.times do |x|
50
60
  base_x = x + offset_x
data/lib/psd/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class PSD
2
- VERSION = "1.4.2"
2
+ VERSION = "1.4.3"
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.2
4
+ version: 1.4.3
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-18 00:00:00.000000000 Z
12
+ date: 2013-11-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake