chunky_png 1.3.9 → 1.3.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +5 -5
  2. data/.standard.yml +16 -0
  3. data/.travis.yml +8 -6
  4. data/.yardopts +1 -1
  5. data/CHANGELOG.rdoc +9 -1
  6. data/CONTRIBUTING.rdoc +17 -8
  7. data/Gemfile +3 -3
  8. data/LICENSE +1 -1
  9. data/README.md +6 -1
  10. data/Rakefile +3 -3
  11. data/benchmarks/decoding_benchmark.rb +17 -17
  12. data/benchmarks/encoding_benchmark.rb +22 -19
  13. data/benchmarks/filesize_benchmark.rb +6 -6
  14. data/bin/rake +29 -0
  15. data/bin/standardrb +29 -0
  16. data/chunky_png.gemspec +19 -15
  17. data/lib/chunky_png.rb +16 -25
  18. data/lib/chunky_png/canvas.rb +28 -27
  19. data/lib/chunky_png/canvas/adam7_interlacing.rb +14 -10
  20. data/lib/chunky_png/canvas/data_url_exporting.rb +1 -3
  21. data/lib/chunky_png/canvas/data_url_importing.rb +1 -3
  22. data/lib/chunky_png/canvas/drawing.rb +28 -43
  23. data/lib/chunky_png/canvas/masking.rb +12 -14
  24. data/lib/chunky_png/canvas/operations.rb +26 -24
  25. data/lib/chunky_png/canvas/png_decoding.rb +36 -32
  26. data/lib/chunky_png/canvas/png_encoding.rb +106 -100
  27. data/lib/chunky_png/canvas/resampling.rb +26 -33
  28. data/lib/chunky_png/canvas/stream_exporting.rb +6 -8
  29. data/lib/chunky_png/canvas/stream_importing.rb +6 -8
  30. data/lib/chunky_png/chunk.rb +69 -60
  31. data/lib/chunky_png/color.rb +211 -206
  32. data/lib/chunky_png/datastream.rb +22 -24
  33. data/lib/chunky_png/dimension.rb +16 -11
  34. data/lib/chunky_png/image.rb +9 -11
  35. data/lib/chunky_png/palette.rb +4 -9
  36. data/lib/chunky_png/point.rb +25 -26
  37. data/lib/chunky_png/rmagick.rb +8 -10
  38. data/lib/chunky_png/vector.rb +26 -29
  39. data/lib/chunky_png/version.rb +1 -1
  40. data/spec/chunky_png/canvas/adam7_interlacing_spec.rb +20 -21
  41. data/spec/chunky_png/canvas/data_url_exporting_spec.rb +8 -5
  42. data/spec/chunky_png/canvas/data_url_importing_spec.rb +5 -6
  43. data/spec/chunky_png/canvas/drawing_spec.rb +46 -38
  44. data/spec/chunky_png/canvas/masking_spec.rb +15 -16
  45. data/spec/chunky_png/canvas/operations_spec.rb +68 -67
  46. data/spec/chunky_png/canvas/png_decoding_spec.rb +37 -38
  47. data/spec/chunky_png/canvas/png_encoding_spec.rb +59 -50
  48. data/spec/chunky_png/canvas/resampling_spec.rb +19 -21
  49. data/spec/chunky_png/canvas/stream_exporting_spec.rb +47 -27
  50. data/spec/chunky_png/canvas/stream_importing_spec.rb +10 -11
  51. data/spec/chunky_png/canvas_spec.rb +57 -52
  52. data/spec/chunky_png/color_spec.rb +115 -114
  53. data/spec/chunky_png/datastream_spec.rb +55 -51
  54. data/spec/chunky_png/dimension_spec.rb +10 -10
  55. data/spec/chunky_png/image_spec.rb +11 -14
  56. data/spec/chunky_png/point_spec.rb +21 -23
  57. data/spec/chunky_png/rmagick_spec.rb +7 -8
  58. data/spec/chunky_png/vector_spec.rb +21 -17
  59. data/spec/chunky_png_spec.rb +2 -2
  60. data/spec/png_suite_spec.rb +35 -40
  61. data/spec/spec_helper.rb +6 -10
  62. data/tasks/benchmarks.rake +7 -8
  63. metadata +38 -7
  64. data/lib/chunky_png/compatibility.rb +0 -15
@@ -1,14 +1,14 @@
1
- require 'chunky_png/canvas/png_encoding'
2
- require 'chunky_png/canvas/png_decoding'
3
- require 'chunky_png/canvas/adam7_interlacing'
4
- require 'chunky_png/canvas/stream_exporting'
5
- require 'chunky_png/canvas/stream_importing'
6
- require 'chunky_png/canvas/data_url_exporting'
7
- require 'chunky_png/canvas/data_url_importing'
8
- require 'chunky_png/canvas/operations'
9
- require 'chunky_png/canvas/drawing'
10
- require 'chunky_png/canvas/resampling'
11
- require 'chunky_png/canvas/masking'
1
+ require "chunky_png/canvas/png_encoding"
2
+ require "chunky_png/canvas/png_decoding"
3
+ require "chunky_png/canvas/adam7_interlacing"
4
+ require "chunky_png/canvas/stream_exporting"
5
+ require "chunky_png/canvas/stream_importing"
6
+ require "chunky_png/canvas/data_url_exporting"
7
+ require "chunky_png/canvas/data_url_importing"
8
+ require "chunky_png/canvas/operations"
9
+ require "chunky_png/canvas/drawing"
10
+ require "chunky_png/canvas/resampling"
11
+ require "chunky_png/canvas/masking"
12
12
 
13
13
  module ChunkyPNG
14
14
  # The ChunkyPNG::Canvas class represents a raster image as a matrix of
@@ -56,7 +56,6 @@ module ChunkyPNG
56
56
  # This array always should have +width * height+ elements.
57
57
  attr_reader :pixels
58
58
 
59
-
60
59
  #################################################################
61
60
  # CONSTRUCTORS
62
61
  #################################################################
@@ -68,7 +67,7 @@ module ChunkyPNG
68
67
  # @param [Integer] height The height in pixels of this canvas
69
68
  # @param [Integer, ...] background_color The initial background color of
70
69
  # this canvas. This can be a color value or any value that
71
- # {ChunkyPNG::Color.parse} can handle.
70
+ # {ChunkyPNG::Color#parse} can handle.
72
71
  #
73
72
  # @overload initialize(width, height, initial)
74
73
  # @param [Integer] width The width in pixels of this canvas
@@ -78,9 +77,10 @@ module ChunkyPNG
78
77
  def initialize(width, height, initial = ChunkyPNG::Color::TRANSPARENT)
79
78
  @width, @height = width, height
80
79
 
81
- if initial.kind_of?(Array)
82
- unless initial.length == width * height
83
- raise ArgumentError, "The initial array should have #{width}x#{height} = #{width*height} elements!"
80
+ if initial.is_a?(Array)
81
+ pixel_count = width * height
82
+ unless initial.length == pixel_count
83
+ raise ArgumentError, "The initial array should have #{width}x#{height} = #{pixel_count} elements!"
84
84
  end
85
85
  @pixels = initial
86
86
  else
@@ -104,7 +104,6 @@ module ChunkyPNG
104
104
  new(canvas.width, canvas.height, canvas.pixels.dup)
105
105
  end
106
106
 
107
-
108
107
  #################################################################
109
108
  # PROPERTIES
110
109
  #################################################################
@@ -143,7 +142,7 @@ module ChunkyPNG
143
142
  #
144
143
  # @param [Integer] x The x-coordinate of the pixel (column)
145
144
  # @param [Integer] y The y-coordinate of the pixel (row)
146
- # @param [Integer] pixel The new color for the provided coordinates.
145
+ # @param [Integer] color The new color for the provided coordinates.
147
146
  # @return [Integer] The new color value for this pixel, i.e.
148
147
  # <tt>color</tt>.
149
148
  def set_pixel(x, y, color)
@@ -155,7 +154,7 @@ module ChunkyPNG
155
154
  #
156
155
  # @param [Integer] x The x-coordinate of the pixel (column)
157
156
  # @param [Integer] y The y-coordinate of the pixel (row)
158
- # @param [Integer] pixel The new color value for the provided coordinates.
157
+ # @param [Integer] color The new color value for the provided coordinates.
159
158
  # @return [Integer] The new color value for this pixel, i.e.
160
159
  # <tt>color</tt>, or <tt>nil</tt> if the coordinates are out of bounds.
161
160
  def set_pixel_if_within_bounds(x, y, color)
@@ -233,7 +232,7 @@ module ChunkyPNG
233
232
  dimension.include?(ChunkyPNG::Point(*point_like))
234
233
  end
235
234
 
236
- alias_method :include?, :include_point?
235
+ alias include? include_point?
237
236
 
238
237
  # Checks whether the given x- and y-coordinate are in the range of the
239
238
  # canvas
@@ -274,11 +273,13 @@ module ChunkyPNG
274
273
  # @return [true, false] True if the size and pixel values of the other
275
274
  # canvas are exactly the same as this canvas's size and pixel values.
276
275
  def eql?(other)
277
- other.kind_of?(self.class) && other.pixels == self.pixels &&
278
- other.width == self.width && other.height == self.height
276
+ other.is_a?(self.class) &&
277
+ other.pixels == pixels &&
278
+ other.width == width &&
279
+ other.height == height
279
280
  end
280
281
 
281
- alias :== :eql?
282
+ alias == eql?
282
283
 
283
284
  #################################################################
284
285
  # EXPORTING
@@ -296,7 +297,7 @@ module ChunkyPNG
296
297
  def inspect
297
298
  inspected = "<#{self.class.name} #{width}x#{height} ["
298
299
  for y in 0...height
299
- inspected << "\n\t[" << row(y).map { |p| ChunkyPNG::Color.to_hex(p) }.join(' ') << ']'
300
+ inspected << "\n\t[" << row(y).map { |p| ChunkyPNG::Color.to_hex(p) }.join(" ") << "]"
300
301
  end
301
302
  inspected << "\n]>"
302
303
  end
@@ -358,13 +359,13 @@ module ChunkyPNG
358
359
 
359
360
  # Throws an exception if the matrix width and height does not match this canvas' dimensions.
360
361
  def assert_size!(matrix_width, matrix_height)
361
- if width != matrix_width
362
+ if width != matrix_width
362
363
  raise ChunkyPNG::ExpectationFailed,
363
- 'The width of the matrix does not match the canvas width!'
364
+ "The width of the matrix does not match the canvas width!"
364
365
  end
365
366
  if height != matrix_height
366
367
  raise ChunkyPNG::ExpectationFailed,
367
- 'The height of the matrix does not match the canvas height!'
368
+ "The height of the matrix does not match the canvas height!"
368
369
  end
369
370
  true
370
371
  end
@@ -1,6 +1,5 @@
1
1
  module ChunkyPNG
2
2
  class Canvas
3
-
4
3
  # Methods for decoding and encoding Adam7 interlacing.
5
4
  #
6
5
  # Adam7 interlacing extracts 7 pass images out of a single image, that can be encoded to a
@@ -8,12 +7,15 @@ module ChunkyPNG
8
7
  # ChunkyPNG canvas and is used to extract the pass images from the original image, or to
9
8
  # reconstruct an original image from separate pass images.
10
9
  module Adam7Interlacing
11
-
12
10
  # Returns an array with the x-shift, x-offset, y-shift and y-offset for the requested pass.
13
11
  # @param [Integer] pass The pass number, should be in 0..6.
14
12
  def adam7_multiplier_offset(pass)
15
- [3 - (pass >> 1), (pass & 1 == 0) ? 0 : 8 >> ((pass + 1) >> 1),
16
- pass == 0 ? 3 : 3 - ((pass - 1) >> 1), (pass == 0 || pass & 1 == 1) ? 0 : 8 >> (pass >> 1)]
13
+ [
14
+ 3 - (pass >> 1),
15
+ pass & 1 == 0 ? 0 : 8 >> ((pass + 1) >> 1),
16
+ pass == 0 ? 3 : 3 - ((pass - 1) >> 1),
17
+ pass == 0 || pass & 1 == 1 ? 0 : 8 >> (pass >> 1),
18
+ ]
17
19
  end
18
20
 
19
21
  # Returns the pixel dimensions of the requested pass.
@@ -22,10 +24,12 @@ module ChunkyPNG
22
24
  # @param [Integer] original_height The height of the original image.
23
25
  def adam7_pass_size(pass, original_width, original_height)
24
26
  x_shift, x_offset, y_shift, y_offset = adam7_multiplier_offset(pass)
25
- [ (original_width - x_offset + (1 << x_shift) - 1) >> x_shift,
26
- (original_height - y_offset + (1 << y_shift) - 1) >> y_shift]
27
+ [
28
+ (original_width - x_offset + (1 << x_shift) - 1) >> x_shift,
29
+ (original_height - y_offset + (1 << y_shift) - 1) >> y_shift,
30
+ ]
27
31
  end
28
-
32
+
29
33
  # Returns an array of the dimension of all the pass images.
30
34
  # @param [Integer] original_width The width of the original image.
31
35
  # @param [Integer] original_height The height of the original image.
@@ -49,7 +53,7 @@ module ChunkyPNG
49
53
  end
50
54
  end
51
55
  end
52
-
56
+
53
57
  # Extracts a pass from a complete image
54
58
  # @param [Integer] pass The pass number, should be in 0..6.
55
59
  # @param [ChunkyPNG::Canvas] canvas The image that is being deconstructed.
@@ -57,13 +61,13 @@ module ChunkyPNG
57
61
  def adam7_extract_pass(pass, canvas)
58
62
  x_shift, x_offset, y_shift, y_offset = adam7_multiplier_offset(pass)
59
63
  sm_pixels = []
60
-
64
+
61
65
  y_offset.step(canvas.height - 1, 1 << y_shift) do |y|
62
66
  x_offset.step(canvas.width - 1, 1 << x_shift) do |x|
63
67
  sm_pixels << canvas[x, y]
64
68
  end
65
69
  end
66
-
70
+
67
71
  new_canvas_args = adam7_pass_size(pass, canvas.width, canvas.height) + [sm_pixels]
68
72
  ChunkyPNG::Canvas.new(*new_canvas_args)
69
73
  end
@@ -1,14 +1,12 @@
1
1
  module ChunkyPNG
2
2
  class Canvas
3
-
4
3
  # Methods to export a canvas to a PNG data URL.
5
4
  module DataUrlExporting
6
-
7
5
  # Exports the canvas as a data url (e.g. data:image/png;base64,<data>) that can
8
6
  # easily be used inline in CSS or HTML.
9
7
  # @return [String] The canvas formatted as a data URL string.
10
8
  def to_data_url
11
- ['data:image/png;base64,', to_blob].pack('A*m').gsub(/\n/, '')
9
+ ["data:image/png;base64,", to_blob].pack("A*m").delete("\n")
12
10
  end
13
11
  end
14
12
  end
@@ -1,9 +1,7 @@
1
1
  module ChunkyPNG
2
2
  class Canvas
3
-
4
3
  # Methods to import a canvas from a PNG data URL.
5
4
  module DataUrlImporting
6
-
7
5
  # Imports a canvas from a PNG data URL.
8
6
  # @param [String] string The data URL string to load from.
9
7
  # @return [Canvas] The imported canvas.
@@ -11,7 +9,7 @@ module ChunkyPNG
11
9
  # formatted PNG data URL (i.e. it should start with "data:image/png;base64,")
12
10
  def from_data_url(string)
13
11
  if string =~ %r[^data:image/png;base64,((?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?)$]
14
- from_blob($1.unpack('m').first)
12
+ from_blob($1.unpack("m").first)
15
13
  else
16
14
  raise SignatureMismatch, "The string was not a properly formatted data URL for a PNG image."
17
15
  end
@@ -1,6 +1,5 @@
1
1
  module ChunkyPNG
2
2
  class Canvas
3
-
4
3
  # Module that adds some primitive drawing methods to {ChunkyPNG::Canvas}.
5
4
  #
6
5
  # All of these methods change the current canvas instance and do not create
@@ -10,7 +9,6 @@ module ChunkyPNG
10
9
  # the bounds of the canvas; these pixels will simply be ignored.
11
10
  # @see ChunkyPNG::Canvas
12
11
  module Drawing
13
-
14
12
  # Composes a pixel on the canvas by alpha blending a color with its
15
13
  # background color.
16
14
  #
@@ -33,44 +31,44 @@ module ChunkyPNG
33
31
  end
34
32
 
35
33
  # Draws a Bezier curve
36
- # @param [Array, Point] A collection of control points
34
+ # @param [Array, Point] points A collection of control points
35
+ # @param [Integer] stroke_color
37
36
  # @return [Chunky:PNG::Canvas] Itself, with the curve drawn
38
37
  def bezier_curve(points, stroke_color = ChunkyPNG::Color::BLACK)
39
38
  points = ChunkyPNG::Vector(*points)
40
39
  case points.length
41
- when 0, 1; return self
42
- when 2; return line(points[0].x, points[0].y, points[1].x, points[1].y, stroke_color)
40
+ when 0, 1 then return self
41
+ when 2 then return line(points[0].x, points[0].y, points[1].x, points[1].y, stroke_color)
43
42
  end
44
43
 
45
- curve_points = Array.new
44
+ curve_points = []
46
45
 
47
46
  t = 0
48
47
  n = points.length - 1
49
- bicof = 0
50
48
 
51
49
  while t <= 100
52
- cur_p = ChunkyPNG::Point.new(0,0)
50
+ bicof = 0
51
+ cur_p = ChunkyPNG::Point.new(0, 0)
53
52
 
54
53
  # Generate a float of t.
55
54
  t_f = t / 100.00
56
55
 
57
- cur_p.x += ((1 - t_f) ** n) * points[0].x
58
- cur_p.y += ((1 - t_f) ** n) * points[0].y
56
+ cur_p.x += ((1 - t_f)**n) * points[0].x
57
+ cur_p.y += ((1 - t_f)**n) * points[0].y
59
58
 
60
59
  for i in 1...points.length - 1
61
- bicof = binomial_coefficient(n , i)
60
+ bicof = binomial_coefficient(n, i)
62
61
 
63
- cur_p.x += (bicof * (1 - t_f) ** (n - i)) * (t_f ** i) * points[i].x
64
- cur_p.y += (bicof * (1 - t_f) ** (n - i)) * (t_f ** i) * points[i].y
62
+ cur_p.x += (bicof * (1 - t_f)**(n - i)) * (t_f**i) * points[i].x
63
+ cur_p.y += (bicof * (1 - t_f)**(n - i)) * (t_f**i) * points[i].y
65
64
  i += 1
66
65
  end
67
66
 
68
- cur_p.x += (t_f ** n) * points[n].x
69
- cur_p.y += (t_f ** n) * points[n].y
67
+ cur_p.x += (t_f**n) * points[n].x
68
+ cur_p.y += (t_f**n) * points[n].y
70
69
 
71
70
  curve_points << cur_p
72
71
 
73
- bicof = 0
74
72
  t += 1
75
73
  end
76
74
 
@@ -127,9 +125,7 @@ module ChunkyPNG
127
125
  w = 0xff - (e_acc >> 8)
128
126
  compose_pixel(x0, y0, ChunkyPNG::Color.fade(stroke_color, w))
129
127
  if inclusive || i > 0
130
- compose_pixel(x0 + sx,
131
- y0 + sy,
132
- ChunkyPNG::Color.fade(stroke_color, 0xff - w))
128
+ compose_pixel(x0 + sx, y0 + sy, ChunkyPNG::Color.fade(stroke_color, 0xff - w))
133
129
  end
134
130
  y0 += sy
135
131
  end
@@ -145,9 +141,7 @@ module ChunkyPNG
145
141
  w = 0xff - (e_acc >> 8)
146
142
  compose_pixel(x0, y0, ChunkyPNG::Color.fade(stroke_color, w))
147
143
  if inclusive || i > 0
148
- compose_pixel(x0 + sx,
149
- y0 + sy,
150
- ChunkyPNG::Color.fade(stroke_color, 0xff - w))
144
+ compose_pixel(x0 + sx, y0 + sy, ChunkyPNG::Color.fade(stroke_color, 0xff - w))
151
145
  end
152
146
  x0 += sx
153
147
  end
@@ -157,23 +151,20 @@ module ChunkyPNG
157
151
  self
158
152
  end
159
153
 
160
- alias_method :line, :line_xiaolin_wu
154
+ alias line line_xiaolin_wu
161
155
 
162
156
  # Draws a polygon on the canvas using the stroke_color, filled using the
163
157
  # fill_color if any.
164
158
  #
165
- # @param [Array, String] The control point vector. Accepts everything
159
+ # @param [Array, String] path The control point vector. Accepts everything
166
160
  # {ChunkyPNG.Vector} accepts.
167
161
  # @param [Integer] stroke_color The stroke color to use for this polygon.
168
162
  # @param [Integer] fill_color The fill color to use for this polygon.
169
163
  # @return [ChunkyPNG::Canvas] Itself, with the polygon drawn.
170
- def polygon(path,
171
- stroke_color = ChunkyPNG::Color::BLACK,
172
- fill_color = ChunkyPNG::Color::TRANSPARENT)
173
-
164
+ def polygon(path, stroke_color = ChunkyPNG::Color::BLACK, fill_color = ChunkyPNG::Color::TRANSPARENT)
174
165
  vector = ChunkyPNG::Vector(*path)
175
166
  if path.length < 3
176
- raise ArgumentError, 'A polygon requires at least 3 points'
167
+ raise ArgumentError, "A polygon requires at least 3 points"
177
168
  end
178
169
 
179
170
  stroke_color = ChunkyPNG::Color.parse(stroke_color)
@@ -215,10 +206,7 @@ module ChunkyPNG
215
206
  # @param [Integer] stroke_color The line color to use for this rectangle.
216
207
  # @param [Integer] fill_color The fill color to use for this rectangle.
217
208
  # @return [ChunkyPNG::Canvas] Itself, with the rectangle drawn.
218
- def rect(x0, y0, x1, y1,
219
- stroke_color = ChunkyPNG::Color::BLACK,
220
- fill_color = ChunkyPNG::Color::TRANSPARENT)
221
-
209
+ def rect(x0, y0, x1, y1, stroke_color = ChunkyPNG::Color::BLACK, fill_color = ChunkyPNG::Color::TRANSPARENT)
222
210
  stroke_color = ChunkyPNG::Color.parse(stroke_color)
223
211
  fill_color = ChunkyPNG::Color.parse(fill_color)
224
212
 
@@ -248,16 +236,13 @@ module ChunkyPNG
248
236
  # @param [Integer] stroke_color The color to use for the line.
249
237
  # @param [Integer] fill_color The color to use that fills the circle.
250
238
  # @return [ChunkyPNG::Canvas] Itself, with the circle drawn.
251
- def circle(x0, y0, radius,
252
- stroke_color = ChunkyPNG::Color::BLACK,
253
- fill_color = ChunkyPNG::Color::TRANSPARENT)
254
-
239
+ def circle(x0, y0, radius, stroke_color = ChunkyPNG::Color::BLACK, fill_color = ChunkyPNG::Color::TRANSPARENT)
255
240
  stroke_color = ChunkyPNG::Color.parse(stroke_color)
256
241
  fill_color = ChunkyPNG::Color.parse(fill_color)
257
242
 
258
243
  f = 1 - radius
259
- ddF_x = 1
260
- ddF_y = -2 * radius
244
+ dd_f_x = 1
245
+ dd_f_y = -2 * radius
261
246
  x = 0
262
247
  y = radius
263
248
 
@@ -272,13 +257,13 @@ module ChunkyPNG
272
257
 
273
258
  if f >= 0
274
259
  y -= 1
275
- ddF_y += 2
276
- f += ddF_y
260
+ dd_f_y += 2
261
+ f += dd_f_y
277
262
  end
278
263
 
279
264
  x += 1
280
- ddF_x += 2
281
- f += ddF_x
265
+ dd_f_x += 2
266
+ f += dd_f_x
282
267
 
283
268
  unless fill_color == ChunkyPNG::Color::TRANSPARENT
284
269
  lines[y] = lines[y] ? [lines[y], x - 1].min : x - 1
@@ -1,13 +1,11 @@
1
1
  module ChunkyPNG
2
2
  class Canvas
3
-
4
3
  # The ChunkyPNG::Canvas::Masking module defines methods to perform masking
5
4
  # and theming operations on a {ChunkyPNG::Canvas}. The module is included into the Canvas class so all
6
5
  # these methods are available on every canvas.
7
6
  #
8
7
  # @see ChunkyPNG::Canvas
9
8
  module Masking
10
-
11
9
  # Creates a new image, based on the current image but with a new theme color.
12
10
  #
13
11
  # This method will replace one color in an image with another image. This is done by
@@ -21,8 +19,8 @@ module ChunkyPNG
21
19
  # @param [Integer] old_theme_color The original theme color in this image.
22
20
  # @param [Integer] new_theme_color The color to replace the old theme color with.
23
21
  # @param [Integer] bg_color The background color on which the theme colored pixels are placed.
24
- # @param [Integer] tolerance The tolerance level to use when extracting the mask image. Five is
25
- # the default; increase this if the masked image does not extract all the required pixels,
22
+ # @param [Integer] tolerance The tolerance level to use when extracting the mask image. Five is
23
+ # the default; increase this if the masked image does not extract all the required pixels,
26
24
  # decrease it if too many pixels get extracted.
27
25
  # @return [ChunkyPNG::Canvas] Returns itself, but with the theme colored pixels changed.
28
26
  # @see #change_theme_color!
@@ -30,9 +28,9 @@ module ChunkyPNG
30
28
  def change_theme_color!(old_theme_color, new_theme_color, bg_color = ChunkyPNG::Color::WHITE, tolerance = 5)
31
29
  base, mask = extract_mask(old_theme_color, bg_color, tolerance)
32
30
  mask.change_mask_color!(new_theme_color)
33
- self.replace!(base.compose!(mask))
31
+ replace!(base.compose!(mask))
34
32
  end
35
-
33
+
36
34
  # Creates a base image and a mask image from an original image that has a particular theme color.
37
35
  # This can be used to easily change a theme color in an image.
38
36
  #
@@ -40,16 +38,16 @@ module ChunkyPNG
40
38
  # these in a mask image. All the other pixels will be stored in a base image. Both images will be
41
39
  # of the exact same size as the original image. The original image will be left untouched.
42
40
  #
43
- # The color of the mask image can be changed with {#change_mask_color!}. This new mask image can
44
- # then be composed upon the base image to create an image with a new theme color. A call to
41
+ # The color of the mask image can be changed with {#change_mask_color!}. This new mask image can
42
+ # then be composed upon the base image to create an image with a new theme color. A call to
45
43
  # {#change_theme_color!} will perform this in one go.
46
44
  #
47
45
  # @param [Integer] mask_color The current theme color.
48
46
  # @param [Integer] bg_color The background color on which the theme colored pixels are applied.
49
- # @param [Integer] tolerance The tolerance level to use when extracting the mask image. Five is
50
- # the default; increase this if the masked image does not extract all the required pixels,
47
+ # @param [Integer] tolerance The tolerance level to use when extracting the mask image. Five is
48
+ # the default; increase this if the masked image does not extract all the required pixels,
51
49
  # decrease it if too many pixels get extracted.
52
- # @return [Array<ChunkyPNG::Canvas, ChunkyPNG::Canvas>] An array with the base canvas and the mask
50
+ # @return [Array<ChunkyPNG::Canvas, ChunkyPNG::Canvas>] An array with the base canvas and the mask
53
51
  # canvas as elements.
54
52
  # @see #change_theme_color!
55
53
  # @see #change_mask_color!
@@ -66,10 +64,10 @@ module ChunkyPNG
66
64
  base_pixels << pixel
67
65
  end
68
66
  end
69
-
70
- [ self.class.new(width, height, base_pixels), self.class.new(width, height, mask_pixels) ]
67
+
68
+ [self.class.new(width, height, base_pixels), self.class.new(width, height, mask_pixels)]
71
69
  end
72
-
70
+
73
71
  # Changes the color of a mask image.
74
72
  #
75
73
  # This method works on a canvas extracted out of another image using the {#extract_mask} method.