chunky_png 0.7.3 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/chunky_png.gemspec +3 -3
- data/lib/chunky_png.rb +1 -1
- data/lib/chunky_png/canvas/drawing.rb +19 -0
- data/lib/chunky_png/color.rb +3 -3
- data/spec/chunky_png/canvas/drawing_spec.rb +9 -0
- data/spec/chunky_png/color_spec.rb +6 -1
- data/spec/resources/rect.png +0 -0
- data/tasks/github-gem.rake +65 -22
- metadata +13 -5
data/chunky_png.gemspec
CHANGED
@@ -3,8 +3,8 @@ Gem::Specification.new do |s|
|
|
3
3
|
|
4
4
|
# Do not change the version and date fields by hand. This will be done
|
5
5
|
# automatically by the gem release script.
|
6
|
-
s.version = "0.
|
7
|
-
s.date = "2010-
|
6
|
+
s.version = "0.8.0"
|
7
|
+
s.date = "2010-07-01"
|
8
8
|
|
9
9
|
s.summary = "Pure ruby library for read/write, chunk-level access to PNG files"
|
10
10
|
s.description = <<-EOT
|
@@ -32,6 +32,6 @@ Gem::Specification.new do |s|
|
|
32
32
|
|
33
33
|
# Do not change the files and test_files fields by hand. This will be done
|
34
34
|
# automatically by the gem release script.
|
35
|
-
s.files = %w(spec/spec_helper.rb spec/resources/ztxt_chunk.png spec/resources/text_chunk.png spec/resources/replaced.png spec/resources/pixelstream.rgb spec/resources/indexed_4bit.png spec/resources/gray_10x10_grayscale.png spec/resources/damaged_signature.png spec/resources/damaged_chunk.png spec/resources/clock_updated.png spec/chunky_png/canvas/png_encoding_spec.rb lib/chunky_png/canvas/stream_exporting.rb spec/resources/gray_10x10.png lib/chunky_png/color.rb lib/chunky_png/canvas/operations.rb spec/resources/clock.png .gitignore spec/resources/gray_10x10_truecolor_alpha.png spec/chunky_png/canvas_spec.rb LICENSE spec/resources/gray_10x10_truecolor.png spec/resources/composited.png spec/resources/clock_mask.png spec/chunky_png/color_spec.rb spec/chunky_png/canvas/adam7_interlacing_spec.rb lib/chunky_png/chunk.rb lib/chunky_png/canvas/stream_importing.rb lib/chunky_png/canvas/png_encoding.rb lib/chunky_png/canvas/adam7_interlacing.rb spec/resources/operations.png spec/chunky_png/canvas/png_decoding_spec.rb lib/chunky_png/canvas.rb Rakefile spec/resources/transparent_gray_10x10.png spec/resources/pixelstream.rgba spec/resources/cropped.png README.rdoc spec/resources/gray_10x10_indexed.png spec/resources/clock_base.png spec/resources/16x16_non_interlaced.png spec/chunky_png_spec.rb spec/chunky_png/canvas/drawing_spec.rb lib/chunky_png/palette.rb lib/chunky_png/datastream.rb chunky_png.gemspec tasks/github-gem.rake spec/resources/pixelstream_reference.png spec/resources/lines.png spec/resources/gray_10x10_grayscale_alpha.png spec/resources/16x16_interlaced.png spec/chunky_png/image_spec.rb lib/chunky_png/canvas/drawing.rb spec/resources/clock_mask_updated.png spec/resources/adam7.png lib/chunky_png/rmagick.rb lib/chunky_png/image.rb spec/chunky_png/rmagick_spec.rb spec/chunky_png/datastream_spec.rb lib/chunky_png/canvas/png_decoding.rb lib/chunky_png.rb)
|
35
|
+
s.files = %w(spec/spec_helper.rb spec/resources/ztxt_chunk.png spec/resources/text_chunk.png spec/resources/replaced.png spec/resources/pixelstream.rgb spec/resources/indexed_4bit.png spec/resources/gray_10x10_grayscale.png spec/resources/damaged_signature.png spec/resources/damaged_chunk.png spec/resources/clock_updated.png spec/chunky_png/canvas/png_encoding_spec.rb lib/chunky_png/canvas/stream_exporting.rb spec/resources/gray_10x10.png lib/chunky_png/color.rb lib/chunky_png/canvas/operations.rb spec/resources/clock.png .gitignore spec/resources/gray_10x10_truecolor_alpha.png spec/chunky_png/canvas_spec.rb LICENSE spec/resources/gray_10x10_truecolor.png spec/resources/composited.png spec/resources/clock_mask.png spec/chunky_png/color_spec.rb spec/chunky_png/canvas/adam7_interlacing_spec.rb lib/chunky_png/chunk.rb lib/chunky_png/canvas/stream_importing.rb lib/chunky_png/canvas/png_encoding.rb lib/chunky_png/canvas/adam7_interlacing.rb spec/resources/operations.png spec/chunky_png/canvas/png_decoding_spec.rb lib/chunky_png/canvas.rb Rakefile spec/resources/transparent_gray_10x10.png spec/resources/pixelstream.rgba spec/resources/cropped.png README.rdoc spec/resources/gray_10x10_indexed.png spec/resources/clock_base.png spec/resources/16x16_non_interlaced.png spec/chunky_png_spec.rb spec/chunky_png/canvas/drawing_spec.rb lib/chunky_png/palette.rb lib/chunky_png/datastream.rb chunky_png.gemspec tasks/github-gem.rake spec/resources/pixelstream_reference.png spec/resources/lines.png spec/resources/gray_10x10_grayscale_alpha.png spec/resources/16x16_interlaced.png spec/chunky_png/image_spec.rb lib/chunky_png/canvas/drawing.rb spec/resources/rect.png spec/resources/clock_mask_updated.png spec/resources/adam7.png lib/chunky_png/rmagick.rb lib/chunky_png/image.rb spec/chunky_png/rmagick_spec.rb spec/chunky_png/datastream_spec.rb lib/chunky_png/canvas/png_decoding.rb lib/chunky_png.rb)
|
36
36
|
s.test_files = %w(spec/chunky_png/canvas/png_encoding_spec.rb spec/chunky_png/canvas_spec.rb spec/chunky_png/color_spec.rb spec/chunky_png/canvas/adam7_interlacing_spec.rb spec/chunky_png/canvas/png_decoding_spec.rb spec/chunky_png_spec.rb spec/chunky_png/canvas/drawing_spec.rb spec/chunky_png/image_spec.rb spec/chunky_png/rmagick_spec.rb spec/chunky_png/datastream_spec.rb)
|
37
37
|
end
|
data/lib/chunky_png.rb
CHANGED
@@ -27,7 +27,7 @@ module ChunkyPNG
|
|
27
27
|
|
28
28
|
# The current version of ChunkyPNG. This value will be updated automatically
|
29
29
|
# by them gem:release rake task.
|
30
|
-
VERSION = "0.
|
30
|
+
VERSION = "0.8.0"
|
31
31
|
|
32
32
|
###################################################
|
33
33
|
# PNG international standard defined constants
|
@@ -59,10 +59,29 @@ module ChunkyPNG
|
|
59
59
|
end
|
60
60
|
point(x1, y1, color)
|
61
61
|
end
|
62
|
+
|
63
|
+
return self
|
62
64
|
end
|
63
65
|
|
64
66
|
alias :line :line_xiaolin_wu
|
65
67
|
|
68
|
+
def rect(x0, y0, x1, y1, line_color, fill_color = ChunkyPNG::COLOR::TRANSPARENT)
|
69
|
+
|
70
|
+
# Fill
|
71
|
+
[x0, x1].min.upto([x0, x1].max) do |x|
|
72
|
+
[y0, y1].min.upto([y0, y1].max) do |y|
|
73
|
+
point(x, y, fill_color)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# Stroke
|
78
|
+
line(x0, y0, x0, y1, line_color)
|
79
|
+
line(x0, y1, x1, y1, line_color)
|
80
|
+
line(x1, y1, x1, y0, line_color)
|
81
|
+
line(x1, y0, x0, y0, line_color)
|
82
|
+
|
83
|
+
return self
|
84
|
+
end
|
66
85
|
end
|
67
86
|
end
|
68
87
|
end
|
data/lib/chunky_png/color.rb
CHANGED
@@ -181,7 +181,7 @@ module ChunkyPNG
|
|
181
181
|
# @return [Integer] The composited color.
|
182
182
|
# @see ChunkyPNG::Color#compose_precise
|
183
183
|
def compose_quick(fg, bg)
|
184
|
-
return fg if opaque?(fg)
|
184
|
+
return fg if opaque?(fg) || fully_transparent?(bg)
|
185
185
|
return bg if fully_transparent?(fg)
|
186
186
|
|
187
187
|
a_com = int8_mult(0xff - a(fg), a(bg))
|
@@ -203,7 +203,7 @@ module ChunkyPNG
|
|
203
203
|
# @return [Integer] The composited color.
|
204
204
|
# @see ChunkyPNG::Color#compose_quick
|
205
205
|
def compose_precise(fg, bg)
|
206
|
-
return fg if opaque?(fg)
|
206
|
+
return fg if opaque?(fg) || fully_transparent?(bg)
|
207
207
|
return bg if fully_transparent?(fg)
|
208
208
|
|
209
209
|
fg_a = a(fg).to_f / MAX
|
@@ -380,7 +380,7 @@ module ChunkyPNG
|
|
380
380
|
WHITE = rgb(255, 255, 255)
|
381
381
|
|
382
382
|
# Fully transparent pixel/color
|
383
|
-
TRANSPARENT = rgba(
|
383
|
+
TRANSPARENT = rgba(0, 0, 0, 0)
|
384
384
|
|
385
385
|
####################################################################
|
386
386
|
# STATIC UTILITY METHODS
|
@@ -26,4 +26,13 @@ describe ChunkyPNG::Canvas::Drawing do
|
|
26
26
|
canvas.should == reference_canvas('lines')
|
27
27
|
end
|
28
28
|
end
|
29
|
+
|
30
|
+
describe '#rect' do
|
31
|
+
it "should draw a rectangle with the correct colors" do
|
32
|
+
canvas = ChunkyPNG::Canvas.new(16, 16, ChunkyPNG::Color::WHITE)
|
33
|
+
canvas.rect(1, 1, 10, 10, ChunkyPNG::Color.rgb(0, 255, 0), ChunkyPNG::Color.rgba(255, 0, 0, 100))
|
34
|
+
canvas.rect(5, 5, 14, 14, ChunkyPNG::Color.rgb(0, 0, 255), ChunkyPNG::Color.rgba(255, 255, 0, 100))
|
35
|
+
canvas.should == reference_canvas('rect')
|
36
|
+
end
|
37
|
+
end
|
29
38
|
end
|
@@ -77,6 +77,11 @@ describe ChunkyPNG::Color do
|
|
77
77
|
end
|
78
78
|
|
79
79
|
describe '#compose' do
|
80
|
+
|
81
|
+
it "should use the foregorund color as is when the background color is fully transparent" do
|
82
|
+
compose(@non_opaque, @fully_transparent).should == @non_opaque
|
83
|
+
end
|
84
|
+
|
80
85
|
it "should use the foregorund color as is when an opaque color is given as foreground color" do
|
81
86
|
compose(@opaque, @white).should == @opaque
|
82
87
|
end
|
@@ -85,7 +90,7 @@ describe ChunkyPNG::Color do
|
|
85
90
|
compose(@fully_transparent, @white).should == @white
|
86
91
|
end
|
87
92
|
|
88
|
-
it "should compose pixels correctly" do
|
93
|
+
it "should compose pixels correctly with both algorithms" do
|
89
94
|
compose_quick(@non_opaque, @white).should == 0x9fc2d6ff
|
90
95
|
compose_precise(@non_opaque, @white).should == 0x9fc2d6ff
|
91
96
|
end
|
Binary file
|
data/tasks/github-gem.rake
CHANGED
@@ -119,24 +119,43 @@ module GithubGem
|
|
119
119
|
checks = [:check_current_branch, :check_clean_status, :check_not_diverged, :check_version]
|
120
120
|
checks.unshift('spec:basic') if has_specs?
|
121
121
|
checks.unshift('test:basic') if has_tests?
|
122
|
-
checks.push << [:check_rubyforge] if gemspec.rubyforge_project
|
122
|
+
# checks.push << [:check_rubyforge] if gemspec.rubyforge_project
|
123
123
|
|
124
124
|
desc "Perform all checks that would occur before a release"
|
125
125
|
task(:release_checks => checks)
|
126
126
|
|
127
127
|
release_tasks = [:release_checks, :set_version, :build, :github_release, :gemcutter_release]
|
128
|
-
release_tasks << [:rubyforge_release] if gemspec.rubyforge_project
|
128
|
+
# release_tasks << [:rubyforge_release] if gemspec.rubyforge_project
|
129
129
|
|
130
|
-
desc "Release a new
|
130
|
+
desc "Release a new version of the gem using the VERSION environment variable"
|
131
131
|
task(:release => release_tasks) { release_task }
|
132
|
+
|
133
|
+
namespace(:release) do
|
134
|
+
desc "Release the next version of the gem, by incrementing the last version segment by 1"
|
135
|
+
task(:next => [:next_version] + release_tasks) { release_task }
|
132
136
|
|
133
|
-
|
134
|
-
|
137
|
+
desc "Release the next version of the gem, using a bump increment (0.0.1)"
|
138
|
+
task(:bump => [:next_bump_version] + release_tasks) { release_task }
|
139
|
+
|
140
|
+
desc "Release the next version of the gem, using a minor increment (0.1.0)"
|
141
|
+
task(:minor => [:next_minor_version] + release_tasks) { release_task }
|
142
|
+
|
143
|
+
desc "Release the next version of the gem, using a major increment (1.0.0)"
|
144
|
+
task(:major => [:next_major_version] + release_tasks) { release_task }
|
145
|
+
end
|
146
|
+
|
147
|
+
# task(:check_rubyforge) { check_rubyforge_task }
|
148
|
+
# task(:rubyforge_release) { rubyforge_release_task }
|
135
149
|
task(:gemcutter_release) { gemcutter_release_task }
|
136
150
|
task(:github_release => [:commit_modified_files, :tag_version]) { github_release_task }
|
137
151
|
task(:tag_version) { tag_version_task }
|
138
152
|
task(:commit_modified_files) { commit_modified_files_task }
|
139
153
|
|
154
|
+
task(:next_version) { next_version_task }
|
155
|
+
task(:next_bump_version) { next_version_task(:bump) }
|
156
|
+
task(:next_minor_version) { next_version_task(:minor) }
|
157
|
+
task(:next_major_version) { next_version_task(:major) }
|
158
|
+
|
140
159
|
desc "Updates the gem release tasks with the latest version on Github"
|
141
160
|
task(:update_tasks) { update_tasks_task }
|
142
161
|
end
|
@@ -160,6 +179,32 @@ module GithubGem
|
|
160
179
|
sh "mv #{gemspec.name}-#{gemspec.version}.gem pkg/#{gemspec.name}-#{gemspec.version}.gem"
|
161
180
|
end
|
162
181
|
|
182
|
+
def newest_version
|
183
|
+
git.tags.map { |tag| tag.name.split('-').last }.compact.map { |v| Gem::Version.new(v) }.max || Gem::Version.new('0.0.0')
|
184
|
+
end
|
185
|
+
|
186
|
+
def next_version(increment = nil)
|
187
|
+
next_version = newest_version.segments
|
188
|
+
increment_index = case increment
|
189
|
+
when :micro then 3
|
190
|
+
when :bump then 2
|
191
|
+
when :minor then 1
|
192
|
+
when :major then 0
|
193
|
+
else next_version.length - 1
|
194
|
+
end
|
195
|
+
|
196
|
+
next_version[increment_index] ||= 0
|
197
|
+
next_version[increment_index] = next_version[increment_index].succ
|
198
|
+
((increment_index + 1)...next_version.length).each { |i| next_version[i] = 0 }
|
199
|
+
|
200
|
+
Gem::Version.new(next_version.join('.'))
|
201
|
+
end
|
202
|
+
|
203
|
+
def next_version_task(increment = nil)
|
204
|
+
ENV['VERSION'] = next_version(increment).version
|
205
|
+
puts "Releasing version #{ENV['VERSION']}..."
|
206
|
+
end
|
207
|
+
|
163
208
|
# Updates the version number in the gemspec file, the VERSION constant in the main
|
164
209
|
# include file and the contents of the VERSION file.
|
165
210
|
def version_task
|
@@ -173,9 +218,7 @@ module GithubGem
|
|
173
218
|
def check_version_task
|
174
219
|
raise "#{ENV['VERSION']} is not a valid version number!" if ENV['VERSION'] && !Gem::Version.correct?(ENV['VERSION'])
|
175
220
|
proposed_version = Gem::Version.new(ENV['VERSION'] || gemspec.version)
|
176
|
-
#
|
177
|
-
newest_version = git.tags.map { |tag| tag.name.split('-').last }.compact.map { |v| Gem::Version.new(v) }.max
|
178
|
-
raise "This version (#{proposed_version}) is not higher than the highest tagged version (#{newest_version})" if newest_version && newest_version >= proposed_version
|
221
|
+
raise "This version (#{proposed_version}) is not higher than the highest tagged version (#{newest_version})" if newest_version >= proposed_version
|
179
222
|
end
|
180
223
|
|
181
224
|
# Checks whether the current branch is not diverged from the remote branch
|
@@ -216,20 +259,20 @@ module GithubGem
|
|
216
259
|
git.push(remote, remote_branch, true)
|
217
260
|
end
|
218
261
|
|
219
|
-
# Checks whether Rubyforge is configured properly
|
220
|
-
def check_rubyforge_task
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
end
|
227
|
-
|
228
|
-
# Task to release the .gem file toRubyforge.
|
229
|
-
def rubyforge_release_task
|
230
|
-
|
231
|
-
end
|
232
|
-
|
262
|
+
# # Checks whether Rubyforge is configured properly
|
263
|
+
# def check_rubyforge_task
|
264
|
+
# # Login no longer necessary when using rubyforge 2.0.0 gem
|
265
|
+
# # raise "Could not login on rubyforge!" unless `rubyforge login 2>&1`.strip.empty?
|
266
|
+
# output = `rubyforge names`.split("\n")
|
267
|
+
# raise "Rubyforge group not found!" unless output.any? { |line| %r[^groups\s*\:.*\b#{Regexp.quote(gemspec.rubyforge_project)}\b.*] =~ line }
|
268
|
+
# raise "Rubyforge package not found!" unless output.any? { |line| %r[^packages\s*\:.*\b#{Regexp.quote(gemspec.name)}\b.*] =~ line }
|
269
|
+
# end
|
270
|
+
|
271
|
+
# # Task to release the .gem file toRubyforge.
|
272
|
+
# def rubyforge_release_task
|
273
|
+
# sh 'rubyforge', 'add_release', gemspec.rubyforge_project, gemspec.name, gemspec.version.to_s, "pkg/#{gemspec.name}-#{gemspec.version}.gem"
|
274
|
+
# end
|
275
|
+
|
233
276
|
def gemcutter_release_task
|
234
277
|
sh "gem push pkg/#{gemspec.name}-#{gemspec.version}.gem"
|
235
278
|
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chunky_png
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 63
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
8
|
+
- 8
|
9
|
+
- 0
|
10
|
+
version: 0.8.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Willem van Bergen
|
@@ -14,16 +15,18 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-07-01 00:00:00 +02:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: rspec
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 13
|
27
30
|
segments:
|
28
31
|
- 1
|
29
32
|
- 2
|
@@ -93,6 +96,7 @@ files:
|
|
93
96
|
- spec/resources/16x16_interlaced.png
|
94
97
|
- spec/chunky_png/image_spec.rb
|
95
98
|
- lib/chunky_png/canvas/drawing.rb
|
99
|
+
- spec/resources/rect.png
|
96
100
|
- spec/resources/clock_mask_updated.png
|
97
101
|
- spec/resources/adam7.png
|
98
102
|
- lib/chunky_png/rmagick.rb
|
@@ -116,23 +120,27 @@ rdoc_options:
|
|
116
120
|
require_paths:
|
117
121
|
- lib
|
118
122
|
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
none: false
|
119
124
|
requirements:
|
120
125
|
- - ">="
|
121
126
|
- !ruby/object:Gem::Version
|
127
|
+
hash: 3
|
122
128
|
segments:
|
123
129
|
- 0
|
124
130
|
version: "0"
|
125
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
none: false
|
126
133
|
requirements:
|
127
134
|
- - ">="
|
128
135
|
- !ruby/object:Gem::Version
|
136
|
+
hash: 3
|
129
137
|
segments:
|
130
138
|
- 0
|
131
139
|
version: "0"
|
132
140
|
requirements: []
|
133
141
|
|
134
142
|
rubyforge_project:
|
135
|
-
rubygems_version: 1.3.
|
143
|
+
rubygems_version: 1.3.7
|
136
144
|
signing_key:
|
137
145
|
specification_version: 3
|
138
146
|
summary: Pure ruby library for read/write, chunk-level access to PNG files
|