psd 1.1.1 → 1.2.0
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 +4 -4
- data/README.md +1 -2
- data/lib/psd/channel_image.rb +2 -2
- data/lib/psd/image.rb +7 -5
- data/lib/psd/image_exports/png.rb +9 -17
- data/lib/psd/image_formats/layer_rle.rb +3 -1
- data/lib/psd/image_formats/rle.rb +13 -18
- data/lib/psd/image_modes/cmyk.rb +1 -1
- data/lib/psd/image_modes/greyscale.rb +2 -2
- data/lib/psd/image_modes/rgb.rb +1 -2
- data/lib/psd/version.rb +1 -1
- data/spec/image_spec.rb +3 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 192aac571ad814510b059521913c776ada912bbe
|
4
|
+
data.tar.gz: 620ccea660e7c7a23ac20807b051f0bc26bd6d98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c27e2806fcfd1091bd58b3888abbd082da8f87e80b263feef7ca31b31c32ca7946caffe0fce89d74685304aa1ab6a6cb3a74f8c41409dd243a7b4be044642c9d
|
7
|
+
data.tar.gz: 25cea6e8c71c7c707bac8b4a8f8dd8a7505af97e86e9a9d1cf6d9e323d14596888f2eb55fa8e4a4b48d37cf1dd7ce02ce013c57bfea91692a1cd198096e72962
|
data/README.md
CHANGED
@@ -94,7 +94,7 @@ psd.tree.descendant_layers.first.width
|
|
94
94
|
PSD files also store various pieces of information in "layer info" blocks. Which blocks a layer has varies from layer-to-layer, but to access them you can do:
|
95
95
|
|
96
96
|
``` ruby
|
97
|
-
psd.tree.descendant_layers.first.
|
97
|
+
psd.tree.descendant_layers.first.text[:font]
|
98
98
|
|
99
99
|
# Returns
|
100
100
|
{:name=>"HelveticaNeue-Light",
|
@@ -184,6 +184,5 @@ PSD.debug = true
|
|
184
184
|
|
185
185
|
There are a few features that are currently missing from PSD.rb.
|
186
186
|
|
187
|
-
* Individual layer image exporting
|
188
187
|
* More image modes + depths for image exporting
|
189
188
|
* A few layer info blocks
|
data/lib/psd/channel_image.rb
CHANGED
@@ -66,7 +66,7 @@ class PSD
|
|
66
66
|
end
|
67
67
|
|
68
68
|
if @channel_data.length != @length
|
69
|
-
PSD.logger.error "#{channel_data.length} read; expected #{@length}"
|
69
|
+
PSD.logger.error "#{@channel_data.length} read; expected #{@length}"
|
70
70
|
end
|
71
71
|
|
72
72
|
process_image_data
|
@@ -85,4 +85,4 @@ class PSD
|
|
85
85
|
end
|
86
86
|
end
|
87
87
|
end
|
88
|
-
end
|
88
|
+
end
|
data/lib/psd/image.rb
CHANGED
@@ -26,22 +26,22 @@ class PSD
|
|
26
26
|
@num_pixels *= 2 if depth == 16
|
27
27
|
|
28
28
|
calculate_length
|
29
|
-
@channel_data =
|
29
|
+
@channel_data = []
|
30
|
+
@pixel_data = []
|
30
31
|
|
31
32
|
@start_pos = @file.tell
|
32
33
|
@end_pos = @start_pos + @length
|
33
34
|
|
34
|
-
@pixel_data = []
|
35
|
-
|
36
35
|
PSD.logger.debug "Image: #{width}x#{height}, length = #{@length}, mode = #{@header.mode_name}, position = #{@start_pos}"
|
37
36
|
|
38
37
|
# Each color channel is represented by a unique ID
|
39
38
|
@channels_info = [
|
40
39
|
{id: 0},
|
41
40
|
{id: 1},
|
42
|
-
{id: 2}
|
43
|
-
{id: -1}
|
41
|
+
{id: 2}
|
44
42
|
]
|
43
|
+
|
44
|
+
@channels_info << {id: -1} if channels == 4
|
45
45
|
end
|
46
46
|
|
47
47
|
# Begins parsing the image by first figuring out the compression format used, and then
|
@@ -103,6 +103,8 @@ class PSD
|
|
103
103
|
when 3 then combine_rgb_channel
|
104
104
|
when 4 then combine_cmyk_channel
|
105
105
|
end
|
106
|
+
|
107
|
+
@channel_data = nil
|
106
108
|
end
|
107
109
|
|
108
110
|
def pixel_step
|
@@ -7,26 +7,18 @@ class PSD::Image
|
|
7
7
|
# Load the image pixels into a PNG file and return a reference to the
|
8
8
|
# data.
|
9
9
|
def to_png
|
10
|
-
|
11
|
-
|
12
|
-
png = ChunkyPNG::Image.new(width.to_i, height.to_i, ChunkyPNG::Color::TRANSPARENT)
|
10
|
+
PSD.logger.debug "Beginning PNG export"
|
11
|
+
png = ChunkyPNG::Image.new(width.to_i, height.to_i, ChunkyPNG::Color::TRANSPARENT)
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
@pixel_data[i+1],
|
20
|
-
@pixel_data[i+2],
|
21
|
-
@pixel_data[i+3]
|
22
|
-
)
|
23
|
-
|
24
|
-
i += 4
|
25
|
-
end
|
13
|
+
i = 0
|
14
|
+
height.times do |y|
|
15
|
+
width.times do |x|
|
16
|
+
png[x,y] = @pixel_data[i]
|
17
|
+
i += 1
|
26
18
|
end
|
19
|
+
end
|
27
20
|
|
28
|
-
|
29
|
-
)
|
21
|
+
png
|
30
22
|
end
|
31
23
|
alias :export :to_png
|
32
24
|
|
@@ -11,30 +11,27 @@ class PSD
|
|
11
11
|
|
12
12
|
def parse_byte_counts!
|
13
13
|
byte_counts = []
|
14
|
-
channels.times do |i|
|
15
|
-
|
16
|
-
byte_counts << @file.read_short
|
17
|
-
end
|
14
|
+
(channels * height).times do |i|
|
15
|
+
byte_counts << @file.read_short
|
18
16
|
end
|
19
17
|
|
20
18
|
return byte_counts
|
21
19
|
end
|
22
20
|
|
23
21
|
def parse_channel_data!
|
24
|
-
chan_pos = 0
|
25
|
-
line_index = 0
|
22
|
+
@chan_pos = 0
|
23
|
+
@line_index = 0
|
26
24
|
|
27
25
|
channels.times do |i|
|
28
|
-
PSD.logger.debug "Parsing RLE channel ##{i}: position = #{chan_pos}, line = #{line_index}"
|
29
|
-
|
30
|
-
line_index += height
|
26
|
+
PSD.logger.debug "Parsing RLE channel ##{i}: position = #{@chan_pos}, line = #{@line_index}"
|
27
|
+
decode_rle_channel
|
28
|
+
@line_index += height
|
31
29
|
end
|
32
30
|
end
|
33
31
|
|
34
|
-
def decode_rle_channel
|
32
|
+
def decode_rle_channel
|
35
33
|
height.times do |j|
|
36
|
-
byte_count = @byte_counts[line_index]
|
37
|
-
line_index += 1
|
34
|
+
byte_count = @byte_counts[@line_index + j]
|
38
35
|
finish = @file.tell + byte_count
|
39
36
|
|
40
37
|
while @file.tell < finish
|
@@ -42,26 +39,24 @@ class PSD
|
|
42
39
|
|
43
40
|
if len < 128
|
44
41
|
len += 1
|
45
|
-
(chan_pos
|
42
|
+
(@chan_pos...@chan_pos+len).each do |k|
|
46
43
|
@channel_data[k] = @file.read(1).bytes.to_a[0]
|
47
44
|
end
|
48
45
|
|
49
|
-
chan_pos += len
|
46
|
+
@chan_pos += len
|
50
47
|
elsif len > 128
|
51
48
|
len ^= 0xff
|
52
49
|
len += 2
|
53
50
|
|
54
51
|
val = @file.read(1).bytes.to_a[0]
|
55
|
-
(chan_pos
|
52
|
+
(@chan_pos...@chan_pos+len).each do |k|
|
56
53
|
@channel_data[k] = val
|
57
54
|
end
|
58
55
|
|
59
|
-
chan_pos += len
|
56
|
+
@chan_pos += len
|
60
57
|
end
|
61
58
|
end
|
62
59
|
end
|
63
|
-
|
64
|
-
return chan_pos
|
65
60
|
end
|
66
61
|
end
|
67
62
|
end
|
data/lib/psd/image_modes/cmyk.rb
CHANGED
@@ -9,11 +9,11 @@ class PSD
|
|
9
9
|
alpha = @channel_data[i]
|
10
10
|
grey = @channel_data[@channel_length + i]
|
11
11
|
|
12
|
-
@pixel_data.push grey,
|
12
|
+
@pixel_data.push ChunkyPNG::Color.greyscale_alpha(grey, alpha)
|
13
13
|
end
|
14
14
|
else
|
15
15
|
(0...@num_pixels).step(pixel_step) do |i|
|
16
|
-
@pixel_data.push
|
16
|
+
@pixel_data.push ChunkyPNG::Color.greyscale(@channel_data[i])
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
data/lib/psd/image_modes/rgb.rb
CHANGED
@@ -12,7 +12,6 @@ class PSD
|
|
12
12
|
a = 255
|
13
13
|
|
14
14
|
@channels_info.each_with_index do |chan, index|
|
15
|
-
next if channels == 3 && chan[:id] == -1
|
16
15
|
val = @channel_data[i + (@channel_length * index)]
|
17
16
|
|
18
17
|
case chan[:id]
|
@@ -23,7 +22,7 @@ class PSD
|
|
23
22
|
end
|
24
23
|
end
|
25
24
|
|
26
|
-
@pixel_data.push r, g, b, a
|
25
|
+
@pixel_data.push ChunkyPNG::Color.rgba(r, g, b, a)
|
27
26
|
end
|
28
27
|
end
|
29
28
|
end
|
data/lib/psd/version.rb
CHANGED
data/spec/image_spec.rb
CHANGED
@@ -16,22 +16,20 @@ describe 'Image Exporting' do
|
|
16
16
|
expect(@psd.image).to_not be_nil
|
17
17
|
expect(@psd.image.width).to eq(1)
|
18
18
|
expect(@psd.image.height).to eq(1)
|
19
|
-
expect(@psd.image.pixel_data).to eq([0, 100, 200, 255])
|
19
|
+
expect(@psd.image.pixel_data).to eq([ChunkyPNG::Color.rgba(0, 100, 200, 255)])
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should be able to skip to the image" do
|
23
23
|
expect(@psd).to_not be_parsed
|
24
24
|
expect(@psd.image.width).to eq(1)
|
25
25
|
expect(@psd.image.height).to eq(1)
|
26
|
-
expect(@psd.image.pixel_data).to eq([0, 100, 200, 255])
|
26
|
+
expect(@psd.image.pixel_data).to eq([ChunkyPNG::Color.rgba(0, 100, 200, 255)])
|
27
27
|
end
|
28
28
|
|
29
29
|
describe "as PNG" do
|
30
30
|
it "should produce a valid PNG object" do
|
31
31
|
expect(@psd.image.to_png).to be_an_instance_of(ChunkyPNG::Image)
|
32
32
|
|
33
|
-
# Ensure it's cached
|
34
|
-
expect(@psd.image.to_png).to be @psd.image.to_png
|
35
33
|
expect(@psd.image.to_png.width).to eq(1)
|
36
34
|
expect(@psd.image.to_png.height).to eq(1)
|
37
35
|
expect(
|
@@ -51,7 +49,7 @@ describe 'Image Exporting' do
|
|
51
49
|
expect(image.width).to eq(1)
|
52
50
|
expect(image.height).to eq(1)
|
53
51
|
|
54
|
-
expect(image.pixel_data).to eq([0, 100, 200, 255])
|
52
|
+
expect(image.pixel_data).to eq([ChunkyPNG::Color.rgba(0, 100, 200, 255)])
|
55
53
|
end
|
56
54
|
|
57
55
|
describe "as PNG" do
|
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
|
+
version: 1.2.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: 2013-09-
|
12
|
+
date: 2013-09-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bindata
|
@@ -211,7 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
211
211
|
version: '0'
|
212
212
|
requirements: []
|
213
213
|
rubyforge_project:
|
214
|
-
rubygems_version: 2.0.
|
214
|
+
rubygems_version: 2.0.8
|
215
215
|
signing_key:
|
216
216
|
specification_version: 4
|
217
217
|
summary: General purpose library for parsing Photoshop files
|