chunky_png 0.5.8 → 0.6.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.
@@ -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.5.8"
7
- s.date = "2010-02-24"
6
+ s.version = "0.6.0"
7
+ s.date = "2010-02-25"
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/pixelstream.rgb spec/resources/indexed_4bit.png spec/resources/gray_10x10_grayscale.png spec/resources/damaged_signature.png spec/resources/damaged_chunk.png lib/chunky_png/rmagick.rb lib/chunky_png/canvas/stream_exporting.rb .gitignore spec/chunky_png/canvas_spec.rb LICENSE spec/resources/gray_10x10_truecolor_alpha.png lib/chunky_png/color.rb lib/chunky_png/canvas/operations.rb spec/resources/gray_10x10_truecolor.png spec/resources/composited.png spec/chunky_png/canvas/adam7_interlacing_spec.rb lib/chunky_png/chunk.rb spec/resources/operations.png spec/chunky_png/canvas/png_decoding_spec.rb spec/chunky_png/canvas/drawing_spec.rb lib/chunky_png/canvas.rb Rakefile tasks/github-gem.rake spec/resources/transparent_gray_10x10.png spec/resources/lines.png spec/resources/cropped.png spec/chunky_png/color_spec.rb lib/chunky_png/canvas/stream_importing.rb lib/chunky_png/canvas/png_encoding.rb lib/chunky_png/canvas/adam7_interlacing.rb README.rdoc spec/resources/gray_10x10_indexed.png spec/resources/16x16_non_interlaced.png spec/chunky_png_spec.rb lib/chunky_png/palette.rb lib/chunky_png/image.rb chunky_png.gemspec spec/resources/pixelstream_reference.png spec/resources/pixelstream.rgba spec/chunky_png/rmagick_spec.rb spec/chunky_png/image_spec.rb spec/chunky_png/datastream_spec.rb lib/chunky_png/canvas/drawing.rb lib/chunky_png.rb spec/resources/text_chunk.png spec/resources/replaced.png spec/resources/adam7.png spec/chunky_png/canvas/png_encoding_spec.rb lib/chunky_png/datastream.rb spec/resources/gray_10x10_grayscale_alpha.png spec/resources/gray_10x10.png spec/resources/16x16_interlaced.png lib/chunky_png/canvas/png_decoding.rb)
36
- s.test_files = %w(spec/chunky_png/canvas_spec.rb spec/chunky_png/canvas/adam7_interlacing_spec.rb spec/chunky_png/canvas/png_decoding_spec.rb spec/chunky_png/canvas/drawing_spec.rb spec/chunky_png/color_spec.rb spec/chunky_png_spec.rb spec/chunky_png/rmagick_spec.rb spec/chunky_png/image_spec.rb spec/chunky_png/datastream_spec.rb spec/chunky_png/canvas/png_encoding_spec.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/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
+ 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
@@ -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.5.8"
30
+ VERSION = "0.6.0"
31
31
 
32
32
  ###################################################
33
33
  # PNG international standard defined constants
@@ -28,6 +28,34 @@ module ChunkyPNG
28
28
  end
29
29
  ChunkyPNG::Canvas.new(crop_width, crop_height, new_pixels)
30
30
  end
31
+
32
+ def change_theme_color!(old_theme_color, new_theme_color, bg_color = ChunkyPNG::Color::WHITE, tolerance = 5)
33
+ base, mask = extract_mask(old_theme_color, bg_color, tolerance)
34
+ mask.change_mask_color!(new_theme_color)
35
+ self.replace(base.compose(mask))
36
+ end
37
+
38
+ def extract_mask(mask_color, bg_color, tolerance = 5)
39
+ base_pixels = []
40
+ mask_pixels = []
41
+
42
+ pixels.each do |pixel|
43
+ if ChunkyPNG::Color.alpha_decomposable?(pixel, mask_color, bg_color, tolerance)
44
+ mask_pixels << ChunkyPNG::Color.decompose_color(pixel, mask_color, bg_color, tolerance)
45
+ base_pixels << bg_color
46
+ else
47
+ mask_pixels << (mask_color & 0xffffff00)
48
+ base_pixels << pixel
49
+ end
50
+ end
51
+
52
+ [ self.class.new(width, height, base_pixels), self.class.new(width, height, mask_pixels) ]
53
+ end
54
+
55
+ def change_mask_color!(new_color)
56
+ raise "This is not a mask image!" if palette.opaque_palette.size != 1
57
+ pixels.map! { |pixel| (new_color & 0xffffff00) | ChunkyPNG::Color.a(pixel) }
58
+ end
31
59
 
32
60
  protected
33
61
 
@@ -89,6 +89,13 @@ module ChunkyPNG
89
89
  def grayscale?
90
90
  all? { |color| Color.grayscale?(color) }
91
91
  end
92
+
93
+ # Returns a palette with all the opaque variants of the colors in this palette.
94
+ # @return [ChunkyPNG::Palette] A new Palette instance with only opaque colors.
95
+ # @see ChunkyPNG::Color#opaque!
96
+ def opaque_palette
97
+ self.class.new(map { |c| ChunkyPNG::Color.opaque!(c) })
98
+ end
92
99
 
93
100
  # Checks whether this palette is suitable for decoding an image from a datastream.
94
101
  #
@@ -54,14 +54,17 @@ describe ChunkyPNG::Canvas do
54
54
  end
55
55
 
56
56
  describe '#compose' do
57
- before(:each) do
58
- @canvas = ChunkyPNG::Canvas.from_file(resource_file('operations.png'))
59
- end
60
-
61
57
  it "should compose pixels correctly" do
58
+ canvas = ChunkyPNG::Canvas.from_file(resource_file('operations.png'))
62
59
  subcanvas = ChunkyPNG::Canvas.new(4, 8, ChunkyPNG::Color.rgba(0, 0, 0, 75))
63
- @canvas.compose(subcanvas, 8, 4)
64
- @canvas.should == reference_canvas('composited')
60
+ canvas.compose(subcanvas, 8, 4)
61
+ canvas.should == reference_canvas('composited')
62
+ end
63
+
64
+ it "should compose a base image and mask correctly" do
65
+ base = reference_canvas('clock_base')
66
+ mask = reference_canvas('clock_mask_updated')
67
+ base.compose(mask).should == reference_canvas('clock_updated')
65
68
  end
66
69
  end
67
70
 
@@ -76,4 +79,53 @@ describe ChunkyPNG::Canvas do
76
79
  @canvas.should == reference_canvas('replaced')
77
80
  end
78
81
  end
82
+
83
+ describe '#change_theme_color!' do
84
+
85
+ before(:each) do
86
+ @theme_color = ChunkyPNG::Color.from_hex('#e10f7a')
87
+ @new_color = ChunkyPNG::Color.from_hex('#ff0000')
88
+ @canvas = reference_canvas('clock')
89
+ end
90
+
91
+ it "should change the theme color correctly" do
92
+ @canvas.change_theme_color!(@theme_color, @new_color)
93
+ @canvas.should == reference_canvas('clock_updated')
94
+ end
95
+ end
96
+
97
+ describe '#extract_mask' do
98
+ before(:each) do
99
+ @mask_color = ChunkyPNG::Color.from_hex('#e10f7a')
100
+ @canvas = reference_canvas('clock')
101
+ end
102
+
103
+ it "should create the correct base and mask image" do
104
+ base, mask = @canvas.extract_mask(@mask_color, ChunkyPNG::Color::WHITE)
105
+ base.should == reference_canvas('clock_base')
106
+ mask.should == reference_canvas('clock_mask')
107
+ end
108
+
109
+ it "should create a mask image with only one opaque color" do
110
+ base, mask = @canvas.extract_mask(@mask_color, ChunkyPNG::Color::WHITE)
111
+ mask.palette.opaque_palette.size.should == 1
112
+ end
113
+ end
114
+
115
+ describe '#change_mask_color!' do
116
+ before(:each) do
117
+ @new_color = ChunkyPNG::Color.from_hex('#ff0000')
118
+ @mask = reference_canvas('clock_mask')
119
+ end
120
+
121
+ it "should replace the mask color correctly" do
122
+ @mask.change_mask_color!(@new_color)
123
+ @mask.should == reference_canvas('clock_mask_updated')
124
+ end
125
+
126
+ it "should still only have one opaque color" do
127
+ @mask.change_mask_color!(@new_color)
128
+ @mask.palette.opaque_palette.size.should == 1
129
+ end
130
+ end
79
131
  end
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chunky_png
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.8
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Willem van Bergen
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-24 00:00:00 -05:00
12
+ date: 2010-02-25 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -34,59 +34,64 @@ extra_rdoc_files:
34
34
  files:
35
35
  - spec/spec_helper.rb
36
36
  - spec/resources/ztxt_chunk.png
37
+ - spec/resources/text_chunk.png
38
+ - spec/resources/replaced.png
37
39
  - spec/resources/pixelstream.rgb
38
40
  - spec/resources/indexed_4bit.png
39
41
  - spec/resources/gray_10x10_grayscale.png
40
42
  - spec/resources/damaged_signature.png
41
43
  - spec/resources/damaged_chunk.png
42
- - lib/chunky_png/rmagick.rb
44
+ - spec/resources/clock_updated.png
45
+ - spec/chunky_png/canvas/png_encoding_spec.rb
43
46
  - lib/chunky_png/canvas/stream_exporting.rb
47
+ - spec/resources/gray_10x10.png
48
+ - lib/chunky_png/color.rb
49
+ - lib/chunky_png/canvas/operations.rb
50
+ - spec/resources/clock.png
44
51
  - .gitignore
52
+ - spec/resources/gray_10x10_truecolor_alpha.png
45
53
  - spec/chunky_png/canvas_spec.rb
46
54
  - LICENSE
47
- - spec/resources/gray_10x10_truecolor_alpha.png
48
- - lib/chunky_png/color.rb
49
- - lib/chunky_png/canvas/operations.rb
50
55
  - spec/resources/gray_10x10_truecolor.png
51
56
  - spec/resources/composited.png
57
+ - spec/resources/clock_mask.png
58
+ - spec/chunky_png/color_spec.rb
52
59
  - spec/chunky_png/canvas/adam7_interlacing_spec.rb
53
60
  - lib/chunky_png/chunk.rb
61
+ - lib/chunky_png/canvas/stream_importing.rb
62
+ - lib/chunky_png/canvas/png_encoding.rb
63
+ - lib/chunky_png/canvas/adam7_interlacing.rb
54
64
  - spec/resources/operations.png
55
65
  - spec/chunky_png/canvas/png_decoding_spec.rb
56
- - spec/chunky_png/canvas/drawing_spec.rb
57
66
  - lib/chunky_png/canvas.rb
58
67
  - Rakefile
59
- - tasks/github-gem.rake
60
68
  - spec/resources/transparent_gray_10x10.png
61
- - spec/resources/lines.png
69
+ - spec/resources/pixelstream.rgba
62
70
  - spec/resources/cropped.png
63
- - spec/chunky_png/color_spec.rb
64
- - lib/chunky_png/canvas/stream_importing.rb
65
- - lib/chunky_png/canvas/png_encoding.rb
66
- - lib/chunky_png/canvas/adam7_interlacing.rb
67
71
  - README.rdoc
68
72
  - spec/resources/gray_10x10_indexed.png
73
+ - spec/resources/clock_base.png
69
74
  - spec/resources/16x16_non_interlaced.png
70
75
  - spec/chunky_png_spec.rb
76
+ - spec/chunky_png/canvas/drawing_spec.rb
71
77
  - lib/chunky_png/palette.rb
72
- - lib/chunky_png/image.rb
78
+ - lib/chunky_png/datastream.rb
73
79
  - chunky_png.gemspec
80
+ - tasks/github-gem.rake
74
81
  - spec/resources/pixelstream_reference.png
75
- - spec/resources/pixelstream.rgba
76
- - spec/chunky_png/rmagick_spec.rb
82
+ - spec/resources/lines.png
83
+ - spec/resources/gray_10x10_grayscale_alpha.png
84
+ - spec/resources/16x16_interlaced.png
77
85
  - spec/chunky_png/image_spec.rb
78
- - spec/chunky_png/datastream_spec.rb
79
86
  - lib/chunky_png/canvas/drawing.rb
80
- - lib/chunky_png.rb
81
- - spec/resources/text_chunk.png
82
- - spec/resources/replaced.png
87
+ - spec/resources/clock_mask_updated.png
83
88
  - spec/resources/adam7.png
84
- - spec/chunky_png/canvas/png_encoding_spec.rb
85
- - lib/chunky_png/datastream.rb
86
- - spec/resources/gray_10x10_grayscale_alpha.png
87
- - spec/resources/gray_10x10.png
88
- - spec/resources/16x16_interlaced.png
89
+ - lib/chunky_png/rmagick.rb
90
+ - lib/chunky_png/image.rb
91
+ - spec/chunky_png/rmagick_spec.rb
92
+ - spec/chunky_png/datastream_spec.rb
89
93
  - lib/chunky_png/canvas/png_decoding.rb
94
+ - lib/chunky_png.rb
90
95
  has_rdoc: true
91
96
  homepage: http://wiki.github.com/wvanbergen/chunky_png
92
97
  licenses: []
@@ -121,13 +126,13 @@ signing_key:
121
126
  specification_version: 3
122
127
  summary: Pure ruby library for read/write, chunk-level access to PNG files
123
128
  test_files:
129
+ - spec/chunky_png/canvas/png_encoding_spec.rb
124
130
  - spec/chunky_png/canvas_spec.rb
131
+ - spec/chunky_png/color_spec.rb
125
132
  - spec/chunky_png/canvas/adam7_interlacing_spec.rb
126
133
  - spec/chunky_png/canvas/png_decoding_spec.rb
127
- - spec/chunky_png/canvas/drawing_spec.rb
128
- - spec/chunky_png/color_spec.rb
129
134
  - spec/chunky_png_spec.rb
130
- - spec/chunky_png/rmagick_spec.rb
135
+ - spec/chunky_png/canvas/drawing_spec.rb
131
136
  - spec/chunky_png/image_spec.rb
137
+ - spec/chunky_png/rmagick_spec.rb
132
138
  - spec/chunky_png/datastream_spec.rb
133
- - spec/chunky_png/canvas/png_encoding_spec.rb