spittle 0.9.1.7 → 0.9.1.8
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.
- data/README.rdoc +3 -2
- data/VERSION +1 -1
- data/lib/spittle/image_data.rb +26 -0
- data/lib/spittle/png/image.rb +51 -45
- data/spec/image_data_spec.rb +14 -0
- data/spec/integration_spec.rb +2 -2
- data/spittle.gemspec +2 -2
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -13,7 +13,7 @@
|
|
13
13
|
|
14
14
|
It takes your PNG's, chews them up and spits out sprites!
|
15
15
|
|
16
|
-
point bin/
|
16
|
+
point bin/sprite at a directory, and watch it sprite away!
|
17
17
|
|
18
18
|
== Installation - standalone
|
19
19
|
|
@@ -51,7 +51,6 @@ Check out examples/sprites if you want to see what spittle can do without doing
|
|
51
51
|
|
52
52
|
== Limitations
|
53
53
|
|
54
|
-
- supports RGB and RGBA color types only (and they must be the same for all images in a sprite)
|
55
54
|
- does not support color profiles (can cause a slight change in color from the source image)
|
56
55
|
- does not support reading interlaced PNGs.
|
57
56
|
|
@@ -64,10 +63,12 @@ Check out examples/sprites if you want to see what spittle can do without doing
|
|
64
63
|
- Supports varying dimensions in source images
|
65
64
|
- Does not regenerate sprites that have not changed
|
66
65
|
- Supports all PNG filter types to improve image compression
|
66
|
+
- supports mixing RGB and RGBA color types
|
67
67
|
|
68
68
|
== Roadmap - by priority
|
69
69
|
|
70
70
|
- Reading interlaced images
|
71
|
+
- Translate between png color spaces automatically.
|
71
72
|
- allow a global css template override
|
72
73
|
- allow per-sprite and global configuration
|
73
74
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.1.
|
1
|
+
0.9.1.8
|
data/lib/spittle/image_data.rb
CHANGED
@@ -1,5 +1,10 @@
|
|
1
|
+
require 'enumerator'
|
2
|
+
|
1
3
|
module Spittle
|
2
4
|
class ImageData
|
5
|
+
RGB_WIDTH = 3
|
6
|
+
RGBA_WIDTH = 4
|
7
|
+
|
3
8
|
def initialize(options = {})
|
4
9
|
@data = (options.delete :data) || []
|
5
10
|
@properties = options
|
@@ -46,6 +51,27 @@ module Spittle
|
|
46
51
|
img
|
47
52
|
end
|
48
53
|
|
54
|
+
def to_rgba( alpha_value=255 )
|
55
|
+
# test that conversion updates pixel width, scanline width
|
56
|
+
|
57
|
+
return self if pixel_width == RGBA_WIDTH
|
58
|
+
|
59
|
+
# so ruby 1.9 has different ideas then 1.8 on how Enumerable should work
|
60
|
+
# 1.9 returns Enumerable object if no block given
|
61
|
+
# 1.8 complains if no block, unless using enum_x methods
|
62
|
+
slice_method = (RUBY_VERSION.include?( "1.9" )) ? :each_slice : :enum_slice
|
63
|
+
|
64
|
+
rgba_data = @data.map do |row|
|
65
|
+
pixels = row.send( slice_method, RGB_WIDTH )
|
66
|
+
pixels.inject([]){|result, pixel| result + pixel + [alpha_value] }
|
67
|
+
end
|
68
|
+
|
69
|
+
ImageData.new( :data => rgba_data,
|
70
|
+
:pixel_width => 4,
|
71
|
+
:scanline_width => (@properties[:scanline_width] / RGB_WIDTH) * RGBA_WIDTH,
|
72
|
+
:name => name)
|
73
|
+
end
|
74
|
+
|
49
75
|
def [](row)
|
50
76
|
@data[row]
|
51
77
|
end
|
data/lib/spittle/png/image.rb
CHANGED
@@ -1,37 +1,47 @@
|
|
1
1
|
module PNG
|
2
|
-
|
3
2
|
class Image
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
#color types
|
4
|
+
RGB = 2
|
5
|
+
RGBA = 6
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def image_data( file_name, options={} )
|
9
|
+
image_options = {:rgba => true}.merge( options )
|
7
10
|
|
8
|
-
|
9
|
-
name = File.basename( file_name, ".png" )
|
11
|
+
png = open(file_name)
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
Image.new( ihdr, idat, name )
|
13
|
+
return png.to_image unless image_options[:rgba]
|
14
|
+
png.to_image.to_rgba
|
14
15
|
end
|
15
|
-
end
|
16
|
-
|
17
|
-
#TODO - rename this 'image_data'
|
18
|
-
def self.image_data( file_name )
|
19
|
-
png = open(file_name)
|
20
|
-
png.to_image
|
21
|
-
end
|
22
16
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
17
|
+
def open( file_name )
|
18
|
+
name = File.basename( file_name, ".png" )
|
19
|
+
|
20
|
+
File.open(file_name, "r") do |f|
|
21
|
+
ihdr, idat = Parser.go!( f )
|
22
|
+
Image.new( ihdr, idat, name )
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def write( file_name, data, options = {} )
|
27
|
+
ihdr = PNG::IHDR.new(data.width, data.height, 8, color_type_of(data.pixel_width))
|
28
|
+
|
29
|
+
Image.new(ihdr, nil, file_name, :rows => data).write( file_name, options)
|
30
|
+
end
|
31
|
+
|
32
|
+
def default_filter_type
|
33
|
+
4 # paeth
|
34
|
+
end
|
27
35
|
|
28
|
-
#
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
36
|
+
private # class methods
|
37
|
+
|
38
|
+
def color_type_of(pixel_width)
|
39
|
+
case pixel_width
|
40
|
+
when 3
|
41
|
+
RGB
|
42
|
+
when 4
|
43
|
+
RGBA
|
44
|
+
end
|
35
45
|
end
|
36
46
|
end
|
37
47
|
|
@@ -56,29 +66,11 @@ module PNG
|
|
56
66
|
end
|
57
67
|
end
|
58
68
|
|
59
|
-
def to_s
|
60
|
-
inspect
|
61
|
-
end
|
62
|
-
|
63
|
-
#color types
|
64
|
-
RGB = 2
|
65
|
-
RGBA = 3
|
66
|
-
|
67
69
|
# check for RGB or RGBA
|
68
70
|
def pixel_width
|
69
71
|
( color_type == RGB ? 3 : 4)
|
70
72
|
end
|
71
73
|
|
72
|
-
|
73
|
-
def scanline_width
|
74
|
-
# + 1 adds filter byte
|
75
|
-
(width * pixel_width) + 1
|
76
|
-
end
|
77
|
-
|
78
|
-
def rows
|
79
|
-
@rows ||= to_image
|
80
|
-
end
|
81
|
-
|
82
74
|
def filter_encoded_rows(filter_type)
|
83
75
|
out = Array.new(height)
|
84
76
|
rows.each_with_index do |row, scanline|
|
@@ -106,11 +98,25 @@ module PNG
|
|
106
98
|
n_out
|
107
99
|
end
|
108
100
|
|
101
|
+
def to_s
|
102
|
+
inspect
|
103
|
+
end
|
104
|
+
|
109
105
|
def inspect
|
110
106
|
"#{@name} (#{height} x #{width}) [color type: #{color_type}, depth: #{depth}]"
|
111
107
|
end
|
108
|
+
|
112
109
|
private
|
113
110
|
|
111
|
+
def scanline_width
|
112
|
+
# + 1 adds filter byte
|
113
|
+
(width * pixel_width) + 1
|
114
|
+
end
|
115
|
+
|
116
|
+
def rows
|
117
|
+
@rows ||= to_image
|
118
|
+
end
|
119
|
+
|
114
120
|
def decode(current, row, data, pixel_width)
|
115
121
|
filter_type = row.shift
|
116
122
|
decode_row(row, data.last_scanline(current), filter_type, pixel_width)
|
data/spec/image_data_spec.rb
CHANGED
@@ -46,4 +46,18 @@ describe Spittle::ImageData do
|
|
46
46
|
it "will return the last scanline given a current index" do
|
47
47
|
@id.last_scanline(1).should == [1,2,3]
|
48
48
|
end
|
49
|
+
|
50
|
+
describe "RGBA conversion" do
|
51
|
+
it "updates pixel width" do
|
52
|
+
@id.to_rgba.pixel_width.should == 4 # RGBA pixel width
|
53
|
+
end
|
54
|
+
|
55
|
+
it "updates scanline width" do
|
56
|
+
@id.to_rgba.scanline_width.should == 4
|
57
|
+
end
|
58
|
+
|
59
|
+
it "puts in an alpha byte with a default value of 255" do
|
60
|
+
@id.to_rgba[0].should == [1,2,3,255]
|
61
|
+
end
|
62
|
+
end
|
49
63
|
end
|
data/spec/integration_spec.rb
CHANGED
@@ -15,8 +15,8 @@ describe 'PNG' do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'can merge one PNG on the left of another' do
|
18
|
-
one = PNG::Image.image_data("#{@img_dir}/lightening.png")
|
19
|
-
two = PNG::Image.image_data("#{@img_dir}/lightening.png")
|
18
|
+
one = PNG::Image.image_data("#{@img_dir}/lightening.png", :rgba => false)
|
19
|
+
two = PNG::Image.image_data("#{@img_dir}/lightening.png", :rgba => false)
|
20
20
|
merged = one.merge_left two
|
21
21
|
PNG::Image.write("#{@tmp_dir}/merge_right_test.png", merged, :filter_type => 0)
|
22
22
|
read("#{@expected_dir}/merge_right_test.png").should == read("#{@tmp_dir}/merge_right_test.png")
|
data/spittle.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{spittle}
|
8
|
-
s.version = "0.9.1.
|
8
|
+
s.version = "0.9.1.8"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["aberant", "tjennings"]
|
12
|
-
s.date = %q{2010-01-
|
12
|
+
s.date = %q{2010-01-04}
|
13
13
|
s.description = %q{Spittle is a pure ruby PNG spriting library. It can be used standalone or as a Rails plugin, see the readme for details.}
|
14
14
|
s.email = ["qzzzq1@gmail.com", "tyler.jennings@gmail.com"]
|
15
15
|
s.executables = ["png_info", "sprite"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spittle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.1.
|
4
|
+
version: 0.9.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- aberant
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2010-01-
|
13
|
+
date: 2010-01-04 00:00:00 -06:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|