chunky_png 1.3.8 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ruby.yml +35 -0
  3. data/.standard.yml +16 -0
  4. data/.yardopts +1 -1
  5. data/CHANGELOG.rdoc +16 -4
  6. data/CONTRIBUTING.rdoc +17 -8
  7. data/Gemfile +12 -4
  8. data/LICENSE +1 -1
  9. data/README.md +15 -9
  10. data/Rakefile +5 -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 +21 -13
  17. data/docs/.gitignore +3 -0
  18. data/docs/CNAME +1 -0
  19. data/docs/_config.yml +9 -0
  20. data/docs/_posts/2010-01-14-memory-efficiency-when-using-ruby.md +136 -0
  21. data/docs/_posts/2010-01-17-ode-to-array-pack-and-string-unpack.md +82 -0
  22. data/docs/_posts/2014-11-07-the-value-of-a-pure-ruby-library.md +61 -0
  23. data/docs/index.md +88 -0
  24. data/lib/chunky_png/canvas/adam7_interlacing.rb +16 -10
  25. data/lib/chunky_png/canvas/data_url_exporting.rb +3 -3
  26. data/lib/chunky_png/canvas/data_url_importing.rb +3 -3
  27. data/lib/chunky_png/canvas/drawing.rb +30 -43
  28. data/lib/chunky_png/canvas/masking.rb +14 -14
  29. data/lib/chunky_png/canvas/operations.rb +28 -24
  30. data/lib/chunky_png/canvas/png_decoding.rb +39 -33
  31. data/lib/chunky_png/canvas/png_encoding.rb +111 -103
  32. data/lib/chunky_png/canvas/resampling.rb +27 -32
  33. data/lib/chunky_png/canvas/stream_exporting.rb +8 -8
  34. data/lib/chunky_png/canvas/stream_importing.rb +8 -8
  35. data/lib/chunky_png/canvas.rb +31 -28
  36. data/lib/chunky_png/chunk.rb +142 -69
  37. data/lib/chunky_png/color.rb +218 -212
  38. data/lib/chunky_png/datastream.rb +24 -30
  39. data/lib/chunky_png/dimension.rb +18 -11
  40. data/lib/chunky_png/image.rb +11 -11
  41. data/lib/chunky_png/palette.rb +13 -14
  42. data/lib/chunky_png/point.rb +27 -26
  43. data/lib/chunky_png/rmagick.rb +10 -10
  44. data/lib/chunky_png/vector.rb +28 -29
  45. data/lib/chunky_png/version.rb +3 -1
  46. data/lib/chunky_png.rb +46 -45
  47. data/spec/chunky_png/canvas/adam7_interlacing_spec.rb +20 -21
  48. data/spec/chunky_png/canvas/data_url_exporting_spec.rb +8 -5
  49. data/spec/chunky_png/canvas/data_url_importing_spec.rb +5 -6
  50. data/spec/chunky_png/canvas/drawing_spec.rb +46 -38
  51. data/spec/chunky_png/canvas/masking_spec.rb +15 -16
  52. data/spec/chunky_png/canvas/operations_spec.rb +68 -67
  53. data/spec/chunky_png/canvas/png_decoding_spec.rb +37 -38
  54. data/spec/chunky_png/canvas/png_encoding_spec.rb +59 -50
  55. data/spec/chunky_png/canvas/resampling_spec.rb +19 -21
  56. data/spec/chunky_png/canvas/stream_exporting_spec.rb +47 -27
  57. data/spec/chunky_png/canvas/stream_importing_spec.rb +10 -11
  58. data/spec/chunky_png/canvas_spec.rb +63 -52
  59. data/spec/chunky_png/color_spec.rb +115 -114
  60. data/spec/chunky_png/datastream_spec.rb +98 -19
  61. data/spec/chunky_png/dimension_spec.rb +10 -10
  62. data/spec/chunky_png/image_spec.rb +11 -14
  63. data/spec/chunky_png/point_spec.rb +21 -23
  64. data/spec/chunky_png/rmagick_spec.rb +7 -8
  65. data/spec/chunky_png/vector_spec.rb +21 -17
  66. data/spec/chunky_png_spec.rb +2 -2
  67. data/spec/png_suite_spec.rb +35 -40
  68. data/spec/resources/itxt_chunk.png +0 -0
  69. data/spec/spec_helper.rb +15 -9
  70. data/tasks/benchmarks.rake +7 -8
  71. metadata +65 -25
  72. data/.travis.yml +0 -16
  73. data/lib/chunky_png/compatibility.rb +0 -15
@@ -1,5 +1,6 @@
1
- module ChunkyPNG
1
+ # frozen-string-literal: true
2
2
 
3
+ module ChunkyPNG
3
4
  # Factory method to return a color value, based on the arguments given.
4
5
  #
5
6
  # @overload Color(r, g, b, a)
@@ -29,15 +30,16 @@ module ChunkyPNG
29
30
  # @raise [ArgumentError] if the arguments weren't understood as a color.
30
31
  # @see ChunkyPNG::Color
31
32
  # @see ChunkyPNG::Color.parse
32
- def self.Color(*args)
33
+ def self.Color(*args) # rubocop:disable Naming/MethodName # API backwards compatibility
33
34
  case args.length
34
- when 1; ChunkyPNG::Color.parse(args.first)
35
- when 2; (ChunkyPNG::Color.parse(args.first) & 0xffffff00) | args[1].to_i
36
- when 3; ChunkyPNG::Color.rgb(*args)
37
- when 4; ChunkyPNG::Color.rgba(*args)
35
+ when 1 then ChunkyPNG::Color.parse(args.first)
36
+ when 2 then (ChunkyPNG::Color.parse(args.first) & 0xffffff00) | args[1].to_i
37
+ when 3 then ChunkyPNG::Color.rgb(*args)
38
+ when 4 then ChunkyPNG::Color.rgba(*args)
38
39
  else raise ArgumentError, "Don't know how to create a color from #{args.inspect}!"
39
40
  end
40
41
  end
42
+ # rubocop:enable Naming/MethodName
41
43
 
42
44
  # The Color module defines methods for handling colors. Within the ChunkyPNG
43
45
  # library, the concepts of pixels and colors are both used, and they are
@@ -78,15 +80,15 @@ module ChunkyPNG
78
80
  #
79
81
  # It supports color numbers, colors in hex notation and named HTML colors.
80
82
  #
81
- # @param [Integer, String] The color value.
83
+ # @param [Integer, String] source The color value.
82
84
  # @return [Integer] The color value, with the opacity applied if one was
83
85
  # given.
84
86
  def parse(source)
85
- return source if source.kind_of?(Integer)
87
+ return source if source.is_a?(Integer)
86
88
  case source.to_s
87
- when /^\d+$/; source.to_s.to_i
88
- when HEX3_COLOR_REGEXP, HEX6_COLOR_REGEXP; from_hex(source.to_s)
89
- when HTML_COLOR_REGEXP; html_color(source.to_s)
89
+ when /^\d+$/ then source.to_s.to_i
90
+ when HEX3_COLOR_REGEXP, HEX6_COLOR_REGEXP then from_hex(source.to_s)
91
+ when HTML_COLOR_REGEXP then html_color(source.to_s)
90
92
  else raise ArgumentError, "Don't know how to create a color from #{source.inspect}!"
91
93
  end
92
94
  end
@@ -157,22 +159,21 @@ module ChunkyPNG
157
159
  # as well as the 3-digit short format (#rgb) for those without.
158
160
  # Color strings may include the prefix "0x" or "#".
159
161
  #
160
- # @param [String] str The color in hex notation. @return [Integer] The
161
- # converted color value.
162
+ # @param [String] hex_value The color in hex notation.
162
163
  # @param [Integer] opacity The opacity value for the color. Overrides any
163
164
  # opacity value given in the hex value if given.
164
165
  # @return [Integer] The color value.
165
166
  # @raise [ArgumentError] if the value given is not a hex color notation.
166
167
  def from_hex(hex_value, opacity = nil)
167
168
  base_color = case hex_value
168
- when HEX3_COLOR_REGEXP
169
- $1.gsub(/([0-9a-f])/i, '\1\1').hex << 8
170
- when HEX6_COLOR_REGEXP
171
- $1.hex << 8
172
- else
173
- raise ArgumentError, "Not a valid hex color notation: #{hex_value.inspect}!"
174
- end
175
- opacity ||= $2 ? $2.hex : 0xff
169
+ when HEX3_COLOR_REGEXP
170
+ $1.gsub(/([0-9a-f])/i, '\1\1').hex << 8
171
+ when HEX6_COLOR_REGEXP
172
+ $1.hex << 8
173
+ else
174
+ raise ArgumentError, "Not a valid hex color notation: #{hex_value.inspect}!"
175
+ end
176
+ opacity ||= $2 ? $2.hex : 0xff
176
177
  base_color | opacity
177
178
  end
178
179
 
@@ -189,18 +190,20 @@ module ChunkyPNG
189
190
  # @param [Fixnum] alpha Defaults to opaque (255).
190
191
  # @return [Integer] The newly constructed color value.
191
192
  # @raise [ArgumentError] if the hsv triple is invalid.
192
- # @see http://en.wikipedia.org/wiki/HSL_and_HSV
193
+ # @see https://en.wikipedia.org/wiki/HSL_and_HSV
193
194
  def from_hsv(hue, saturation, value, alpha = 255)
194
- raise ArgumentError, "Hue must be between 0 and 360" unless (0..360).include?(hue)
195
- raise ArgumentError, "Saturation must be between 0 and 1" unless (0..1).include?(saturation)
196
- raise ArgumentError, "Value/brightness must be between 0 and 1" unless (0..1).include?(value)
195
+ raise ArgumentError, "Hue must be between 0 and 360" unless (0..360).cover?(hue)
196
+ raise ArgumentError, "Saturation must be between 0 and 1" unless (0..1).cover?(saturation)
197
+ raise ArgumentError, "Value/brightness must be between 0 and 1" unless (0..1).cover?(value)
198
+
197
199
  chroma = value * saturation
198
200
  rgb = cylindrical_to_cubic(hue, saturation, value, chroma)
199
201
  rgb.map! { |component| ((component + value - chroma) * 255).to_i }
200
202
  rgb << alpha
201
- self.rgba(*rgb)
203
+ rgba(*rgb)
202
204
  end
203
- alias_method :from_hsb, :from_hsv
205
+
206
+ alias from_hsb from_hsv
204
207
 
205
208
  # Creates a new color from an HSL triple.
206
209
  #
@@ -213,16 +216,17 @@ module ChunkyPNG
213
216
  # @param [Fixnum] alpha Defaults to opaque (255).
214
217
  # @return [Integer] The newly constructed color value.
215
218
  # @raise [ArgumentError] if the hsl triple is invalid.
216
- # @see http://en.wikipedia.org/wiki/HSL_and_HSV
219
+ # @see https://en.wikipedia.org/wiki/HSL_and_HSV
217
220
  def from_hsl(hue, saturation, lightness, alpha = 255)
218
- raise ArgumentError, "Hue #{hue} was not between 0 and 360" unless (0..360).include?(hue)
219
- raise ArgumentError, "Saturation #{saturation} was not between 0 and 1" unless (0..1).include?(saturation)
220
- raise ArgumentError, "Lightness #{lightness} was not between 0 and 1" unless (0..1).include?(lightness)
221
+ raise ArgumentError, "Hue #{hue} was not between 0 and 360" unless (0..360).cover?(hue)
222
+ raise ArgumentError, "Saturation #{saturation} was not between 0 and 1" unless (0..1).cover?(saturation)
223
+ raise ArgumentError, "Lightness #{lightness} was not between 0 and 1" unless (0..1).cover?(lightness)
224
+
221
225
  chroma = (1 - (2 * lightness - 1).abs) * saturation
222
226
  rgb = cylindrical_to_cubic(hue, saturation, lightness, chroma)
223
227
  rgb.map! { |component| ((component + lightness - 0.5 * chroma) * 255).to_i }
224
228
  rgb << alpha
225
- self.rgba(*rgb)
229
+ rgba(*rgb)
226
230
  end
227
231
 
228
232
  # Convert one HSL or HSV triple and associated chroma to a scaled rgb triple
@@ -243,20 +247,19 @@ module ChunkyPNG
243
247
  # @param [Fixnum] chroma The associated chroma value.
244
248
  # @return [Array<Fixnum>] A scaled r,g,b triple. Scheme-dependent
245
249
  # adjustments are still needed to reach the true r,g,b values.
246
- # @see http://en.wikipedia.org/wiki/HSL_and_HSV
247
- # @see http://www.tomjewett.com/colors/hsb.html
250
+ # @see https://en.wikipedia.org/wiki/HSL_and_HSV
248
251
  # @private
249
252
  def cylindrical_to_cubic(hue, saturation, y_component, chroma)
250
253
  hue_prime = hue.fdiv(60)
251
254
  x = chroma * (1 - (hue_prime % 2 - 1).abs)
252
255
 
253
256
  case hue_prime
254
- when (0...1); [chroma, x, 0]
255
- when (1...2); [x, chroma, 0]
256
- when (2...3); [0, chroma, x]
257
- when (3...4); [0, x, chroma]
258
- when (4...5); [x, 0, chroma]
259
- when (5..6); [chroma, 0, x]
257
+ when (0...1) then [chroma, x, 0]
258
+ when (1...2) then [x, chroma, 0]
259
+ when (2...3) then [0, chroma, x]
260
+ when (3...4) then [0, x, chroma]
261
+ when (4...5) then [x, 0, chroma]
262
+ when (5..6) then [chroma, 0, x]
260
263
  end
261
264
  end
262
265
  private :cylindrical_to_cubic
@@ -392,7 +395,7 @@ module ChunkyPNG
392
395
  rgba(new_r, new_g, new_b, new_a)
393
396
  end
394
397
 
395
- alias :compose :compose_quick
398
+ alias compose compose_quick
396
399
 
397
400
  # Blends the foreground and background color by taking the average of
398
401
  # the components.
@@ -413,7 +416,7 @@ module ChunkyPNG
413
416
  # @param [Integer] fg The foreground color.
414
417
  # @param [Integer] bg The background color.
415
418
  # @param [Integer] alpha The blending factor (fixed 8bit)
416
- # @param [Integer] The interpolated color.
419
+ # @return [Integer] The interpolated color.
417
420
  def interpolate_quick(fg, bg, alpha)
418
421
  return fg if alpha >= 255
419
422
  return bg if alpha <= 0
@@ -499,7 +502,7 @@ module ChunkyPNG
499
502
  # @see #decompose_alpha
500
503
  def alpha_decomposable?(color, mask, bg, tolerance = 1)
501
504
  components = decompose_alpha_components(color, mask, bg)
502
- sum = components.inject(0) { |a,b| a + b }
505
+ sum = components.inject(0) { |a, b| a + b }
503
506
  max = components.max * 3
504
507
  components.max <= 255 && components.min >= 0 && (sum + tolerance * 3) >= max
505
508
  end
@@ -520,7 +523,7 @@ module ChunkyPNG
520
523
  # @see #alpha_decomposable?
521
524
  def decompose_alpha(color, mask, bg)
522
525
  components = decompose_alpha_components(color, mask, bg)
523
- (components.inject(0) { |a,b| a + b } / 3.0).round
526
+ (components.inject(0) { |a, b| a + b } / 3.0).round
524
527
  end
525
528
 
526
529
  # Decomposes an alpha channel for either the r, g or b color channel.
@@ -552,7 +555,7 @@ module ChunkyPNG
552
555
  [
553
556
  decompose_alpha_component(:r, color, mask, bg),
554
557
  decompose_alpha_component(:g, color, mask, bg),
555
- decompose_alpha_component(:b, color, mask, bg)
558
+ decompose_alpha_component(:b, color, mask, bg),
556
559
  ]
557
560
  end
558
561
 
@@ -563,10 +566,11 @@ module ChunkyPNG
563
566
  # Returns a string representing this color using hex notation (i.e.
564
567
  # #rrggbbaa).
565
568
  #
566
- # @param [Integer] value The color to convert.
569
+ # @param [Integer] color The color to convert.
570
+ # @param [Boolean] include_alpha
567
571
  # @return [String] The color in hex notation, starting with a pound sign.
568
572
  def to_hex(color, include_alpha = true)
569
- include_alpha ? ('#%08x' % color) : ('#%06x' % [color >> 8])
573
+ include_alpha ? ("#%08x" % color) : ("#%06x" % [color >> 8])
570
574
  end
571
575
 
572
576
  # Returns an array with the separate HSV components of a color.
@@ -587,7 +591,7 @@ module ChunkyPNG
587
591
  # @return [Array[2]] The value of the color (0-1)
588
592
  # @return [Array[3]] Optional fourth element for alpha, included if
589
593
  # include_alpha=true (0-255)
590
- # @see http://en.wikipedia.org/wiki/HSL_and_HSV
594
+ # @see https://en.wikipedia.org/wiki/HSL_and_HSV
591
595
  def to_hsv(color, include_alpha = false)
592
596
  hue, chroma, max, _ = hue_and_chroma(color)
593
597
  value = max
@@ -596,7 +600,8 @@ module ChunkyPNG
596
600
  include_alpha ? [hue, saturation, value, a(color)] :
597
601
  [hue, saturation, value]
598
602
  end
599
- alias_method :to_hsb, :to_hsv
603
+
604
+ alias to_hsb to_hsv
600
605
 
601
606
  # Returns an array with the separate HSL components of a color.
602
607
  #
@@ -615,7 +620,7 @@ module ChunkyPNG
615
620
  # @return [Array<Fixnum>[2]] The lightness of the color (0-1)
616
621
  # @return [Array<Fixnum>[3]] Optional fourth element for alpha, included if
617
622
  # include_alpha=true (0-255)
618
- # @see http://en.wikipedia.org/wiki/HSL_and_HSV
623
+ # @see https://en.wikipedia.org/wiki/HSL_and_HSV
619
624
  def to_hsl(color, include_alpha = false)
620
625
  hue, chroma, max, min = hue_and_chroma(color)
621
626
  lightness = 0.5 * (max + min)
@@ -629,29 +634,30 @@ module ChunkyPNG
629
634
  # a ChunkPNG color. This logic is shared by the cylindrical HSV/HSB and HSL
630
635
  # color space models.
631
636
  #
632
- # @param [Integer] A ChunkyPNG color.
637
+ # @param [Integer] color A ChunkyPNG color.
633
638
  # @return [Fixnum] hue The hue of the color (0-360)
634
639
  # @return [Fixnum] chroma The chroma of the color (0-1)
635
640
  # @return [Fixnum] max The magnitude of the largest scaled rgb component (0-1)
636
641
  # @return [Fixnum] min The magnitude of the smallest scaled rgb component (0-1)
637
642
  # @private
638
643
  def hue_and_chroma(color)
639
- scaled_rgb = to_truecolor_bytes(color)
644
+ scaled_rgb = to_truecolor_bytes(color)
640
645
  scaled_rgb.map! { |component| component.fdiv(255) }
641
646
  min, max = scaled_rgb.minmax
642
647
  chroma = max - min
643
648
 
644
649
  r, g, b = scaled_rgb
645
650
  hue_prime = chroma.zero? ? 0 : case max
646
- when r; (g - b).fdiv(chroma)
647
- when g; (b - r).fdiv(chroma) + 2
648
- when b; (r - g).fdiv(chroma) + 4
651
+ when r then (g - b).fdiv(chroma)
652
+ when g then (b - r).fdiv(chroma) + 2
653
+ when b then (r - g).fdiv(chroma) + 4
649
654
  else 0
650
655
  end
651
656
  hue = 60 * hue_prime
652
657
 
653
- return hue.round, chroma, max, min
658
+ [hue.round, chroma, max, min]
654
659
  end
660
+
655
661
  private :hue_and_chroma
656
662
 
657
663
  # Returns an array with the separate RGBA values for this color.
@@ -735,153 +741,153 @@ module ChunkyPNG
735
741
 
736
742
  # @return [Hash<Symbol, Integer>] All the predefined color names in HTML.
737
743
  PREDEFINED_COLORS = {
738
- :aliceblue => 0xf0f8ff00,
739
- :antiquewhite => 0xfaebd700,
740
- :aqua => 0x00ffff00,
741
- :aquamarine => 0x7fffd400,
742
- :azure => 0xf0ffff00,
743
- :beige => 0xf5f5dc00,
744
- :bisque => 0xffe4c400,
745
- :black => 0x00000000,
746
- :blanchedalmond => 0xffebcd00,
747
- :blue => 0x0000ff00,
748
- :blueviolet => 0x8a2be200,
749
- :brown => 0xa52a2a00,
750
- :burlywood => 0xdeb88700,
751
- :cadetblue => 0x5f9ea000,
752
- :chartreuse => 0x7fff0000,
753
- :chocolate => 0xd2691e00,
754
- :coral => 0xff7f5000,
755
- :cornflowerblue => 0x6495ed00,
756
- :cornsilk => 0xfff8dc00,
757
- :crimson => 0xdc143c00,
758
- :cyan => 0x00ffff00,
759
- :darkblue => 0x00008b00,
760
- :darkcyan => 0x008b8b00,
761
- :darkgoldenrod => 0xb8860b00,
762
- :darkgray => 0xa9a9a900,
763
- :darkgrey => 0xa9a9a900,
764
- :darkgreen => 0x00640000,
765
- :darkkhaki => 0xbdb76b00,
766
- :darkmagenta => 0x8b008b00,
767
- :darkolivegreen => 0x556b2f00,
768
- :darkorange => 0xff8c0000,
769
- :darkorchid => 0x9932cc00,
770
- :darkred => 0x8b000000,
771
- :darksalmon => 0xe9967a00,
772
- :darkseagreen => 0x8fbc8f00,
773
- :darkslateblue => 0x483d8b00,
774
- :darkslategray => 0x2f4f4f00,
775
- :darkslategrey => 0x2f4f4f00,
776
- :darkturquoise => 0x00ced100,
777
- :darkviolet => 0x9400d300,
778
- :deeppink => 0xff149300,
779
- :deepskyblue => 0x00bfff00,
780
- :dimgray => 0x69696900,
781
- :dimgrey => 0x69696900,
782
- :dodgerblue => 0x1e90ff00,
783
- :firebrick => 0xb2222200,
784
- :floralwhite => 0xfffaf000,
785
- :forestgreen => 0x228b2200,
786
- :fuchsia => 0xff00ff00,
787
- :gainsboro => 0xdcdcdc00,
788
- :ghostwhite => 0xf8f8ff00,
789
- :gold => 0xffd70000,
790
- :goldenrod => 0xdaa52000,
791
- :gray => 0x80808000,
792
- :grey => 0x80808000,
793
- :green => 0x00800000,
794
- :greenyellow => 0xadff2f00,
795
- :honeydew => 0xf0fff000,
796
- :hotpink => 0xff69b400,
797
- :indianred => 0xcd5c5c00,
798
- :indigo => 0x4b008200,
799
- :ivory => 0xfffff000,
800
- :khaki => 0xf0e68c00,
801
- :lavender => 0xe6e6fa00,
802
- :lavenderblush => 0xfff0f500,
803
- :lawngreen => 0x7cfc0000,
804
- :lemonchiffon => 0xfffacd00,
805
- :lightblue => 0xadd8e600,
806
- :lightcoral => 0xf0808000,
807
- :lightcyan => 0xe0ffff00,
808
- :lightgoldenrodyellow => 0xfafad200,
809
- :lightgray => 0xd3d3d300,
810
- :lightgrey => 0xd3d3d300,
811
- :lightgreen => 0x90ee9000,
812
- :lightpink => 0xffb6c100,
813
- :lightsalmon => 0xffa07a00,
814
- :lightseagreen => 0x20b2aa00,
815
- :lightskyblue => 0x87cefa00,
816
- :lightslategray => 0x77889900,
817
- :lightslategrey => 0x77889900,
818
- :lightsteelblue => 0xb0c4de00,
819
- :lightyellow => 0xffffe000,
820
- :lime => 0x00ff0000,
821
- :limegreen => 0x32cd3200,
822
- :linen => 0xfaf0e600,
823
- :magenta => 0xff00ff00,
824
- :maroon => 0x80000000,
825
- :mediumaquamarine => 0x66cdaa00,
826
- :mediumblue => 0x0000cd00,
827
- :mediumorchid => 0xba55d300,
828
- :mediumpurple => 0x9370d800,
829
- :mediumseagreen => 0x3cb37100,
830
- :mediumslateblue => 0x7b68ee00,
831
- :mediumspringgreen => 0x00fa9a00,
832
- :mediumturquoise => 0x48d1cc00,
833
- :mediumvioletred => 0xc7158500,
834
- :midnightblue => 0x19197000,
835
- :mintcream => 0xf5fffa00,
836
- :mistyrose => 0xffe4e100,
837
- :moccasin => 0xffe4b500,
838
- :navajowhite => 0xffdead00,
839
- :navy => 0x00008000,
840
- :oldlace => 0xfdf5e600,
841
- :olive => 0x80800000,
842
- :olivedrab => 0x6b8e2300,
843
- :orange => 0xffa50000,
844
- :orangered => 0xff450000,
845
- :orchid => 0xda70d600,
846
- :palegoldenrod => 0xeee8aa00,
847
- :palegreen => 0x98fb9800,
848
- :paleturquoise => 0xafeeee00,
849
- :palevioletred => 0xd8709300,
850
- :papayawhip => 0xffefd500,
851
- :peachpuff => 0xffdab900,
852
- :peru => 0xcd853f00,
853
- :pink => 0xffc0cb00,
854
- :plum => 0xdda0dd00,
855
- :powderblue => 0xb0e0e600,
856
- :purple => 0x80008000,
857
- :red => 0xff000000,
858
- :rosybrown => 0xbc8f8f00,
859
- :royalblue => 0x4169e100,
860
- :saddlebrown => 0x8b451300,
861
- :salmon => 0xfa807200,
862
- :sandybrown => 0xf4a46000,
863
- :seagreen => 0x2e8b5700,
864
- :seashell => 0xfff5ee00,
865
- :sienna => 0xa0522d00,
866
- :silver => 0xc0c0c000,
867
- :skyblue => 0x87ceeb00,
868
- :slateblue => 0x6a5acd00,
869
- :slategray => 0x70809000,
870
- :slategrey => 0x70809000,
871
- :snow => 0xfffafa00,
872
- :springgreen => 0x00ff7f00,
873
- :steelblue => 0x4682b400,
874
- :tan => 0xd2b48c00,
875
- :teal => 0x00808000,
876
- :thistle => 0xd8bfd800,
877
- :tomato => 0xff634700,
878
- :turquoise => 0x40e0d000,
879
- :violet => 0xee82ee00,
880
- :wheat => 0xf5deb300,
881
- :white => 0xffffff00,
882
- :whitesmoke => 0xf5f5f500,
883
- :yellow => 0xffff0000,
884
- :yellowgreen => 0x9acd3200
744
+ aliceblue: 0xf0f8ff00,
745
+ antiquewhite: 0xfaebd700,
746
+ aqua: 0x00ffff00,
747
+ aquamarine: 0x7fffd400,
748
+ azure: 0xf0ffff00,
749
+ beige: 0xf5f5dc00,
750
+ bisque: 0xffe4c400,
751
+ black: 0x00000000,
752
+ blanchedalmond: 0xffebcd00,
753
+ blue: 0x0000ff00,
754
+ blueviolet: 0x8a2be200,
755
+ brown: 0xa52a2a00,
756
+ burlywood: 0xdeb88700,
757
+ cadetblue: 0x5f9ea000,
758
+ chartreuse: 0x7fff0000,
759
+ chocolate: 0xd2691e00,
760
+ coral: 0xff7f5000,
761
+ cornflowerblue: 0x6495ed00,
762
+ cornsilk: 0xfff8dc00,
763
+ crimson: 0xdc143c00,
764
+ cyan: 0x00ffff00,
765
+ darkblue: 0x00008b00,
766
+ darkcyan: 0x008b8b00,
767
+ darkgoldenrod: 0xb8860b00,
768
+ darkgray: 0xa9a9a900,
769
+ darkgrey: 0xa9a9a900,
770
+ darkgreen: 0x00640000,
771
+ darkkhaki: 0xbdb76b00,
772
+ darkmagenta: 0x8b008b00,
773
+ darkolivegreen: 0x556b2f00,
774
+ darkorange: 0xff8c0000,
775
+ darkorchid: 0x9932cc00,
776
+ darkred: 0x8b000000,
777
+ darksalmon: 0xe9967a00,
778
+ darkseagreen: 0x8fbc8f00,
779
+ darkslateblue: 0x483d8b00,
780
+ darkslategray: 0x2f4f4f00,
781
+ darkslategrey: 0x2f4f4f00,
782
+ darkturquoise: 0x00ced100,
783
+ darkviolet: 0x9400d300,
784
+ deeppink: 0xff149300,
785
+ deepskyblue: 0x00bfff00,
786
+ dimgray: 0x69696900,
787
+ dimgrey: 0x69696900,
788
+ dodgerblue: 0x1e90ff00,
789
+ firebrick: 0xb2222200,
790
+ floralwhite: 0xfffaf000,
791
+ forestgreen: 0x228b2200,
792
+ fuchsia: 0xff00ff00,
793
+ gainsboro: 0xdcdcdc00,
794
+ ghostwhite: 0xf8f8ff00,
795
+ gold: 0xffd70000,
796
+ goldenrod: 0xdaa52000,
797
+ gray: 0x80808000,
798
+ grey: 0x80808000,
799
+ green: 0x00800000,
800
+ greenyellow: 0xadff2f00,
801
+ honeydew: 0xf0fff000,
802
+ hotpink: 0xff69b400,
803
+ indianred: 0xcd5c5c00,
804
+ indigo: 0x4b008200,
805
+ ivory: 0xfffff000,
806
+ khaki: 0xf0e68c00,
807
+ lavender: 0xe6e6fa00,
808
+ lavenderblush: 0xfff0f500,
809
+ lawngreen: 0x7cfc0000,
810
+ lemonchiffon: 0xfffacd00,
811
+ lightblue: 0xadd8e600,
812
+ lightcoral: 0xf0808000,
813
+ lightcyan: 0xe0ffff00,
814
+ lightgoldenrodyellow: 0xfafad200,
815
+ lightgray: 0xd3d3d300,
816
+ lightgrey: 0xd3d3d300,
817
+ lightgreen: 0x90ee9000,
818
+ lightpink: 0xffb6c100,
819
+ lightsalmon: 0xffa07a00,
820
+ lightseagreen: 0x20b2aa00,
821
+ lightskyblue: 0x87cefa00,
822
+ lightslategray: 0x77889900,
823
+ lightslategrey: 0x77889900,
824
+ lightsteelblue: 0xb0c4de00,
825
+ lightyellow: 0xffffe000,
826
+ lime: 0x00ff0000,
827
+ limegreen: 0x32cd3200,
828
+ linen: 0xfaf0e600,
829
+ magenta: 0xff00ff00,
830
+ maroon: 0x80000000,
831
+ mediumaquamarine: 0x66cdaa00,
832
+ mediumblue: 0x0000cd00,
833
+ mediumorchid: 0xba55d300,
834
+ mediumpurple: 0x9370d800,
835
+ mediumseagreen: 0x3cb37100,
836
+ mediumslateblue: 0x7b68ee00,
837
+ mediumspringgreen: 0x00fa9a00,
838
+ mediumturquoise: 0x48d1cc00,
839
+ mediumvioletred: 0xc7158500,
840
+ midnightblue: 0x19197000,
841
+ mintcream: 0xf5fffa00,
842
+ mistyrose: 0xffe4e100,
843
+ moccasin: 0xffe4b500,
844
+ navajowhite: 0xffdead00,
845
+ navy: 0x00008000,
846
+ oldlace: 0xfdf5e600,
847
+ olive: 0x80800000,
848
+ olivedrab: 0x6b8e2300,
849
+ orange: 0xffa50000,
850
+ orangered: 0xff450000,
851
+ orchid: 0xda70d600,
852
+ palegoldenrod: 0xeee8aa00,
853
+ palegreen: 0x98fb9800,
854
+ paleturquoise: 0xafeeee00,
855
+ palevioletred: 0xd8709300,
856
+ papayawhip: 0xffefd500,
857
+ peachpuff: 0xffdab900,
858
+ peru: 0xcd853f00,
859
+ pink: 0xffc0cb00,
860
+ plum: 0xdda0dd00,
861
+ powderblue: 0xb0e0e600,
862
+ purple: 0x80008000,
863
+ red: 0xff000000,
864
+ rosybrown: 0xbc8f8f00,
865
+ royalblue: 0x4169e100,
866
+ saddlebrown: 0x8b451300,
867
+ salmon: 0xfa807200,
868
+ sandybrown: 0xf4a46000,
869
+ seagreen: 0x2e8b5700,
870
+ seashell: 0xfff5ee00,
871
+ sienna: 0xa0522d00,
872
+ silver: 0xc0c0c000,
873
+ skyblue: 0x87ceeb00,
874
+ slateblue: 0x6a5acd00,
875
+ slategray: 0x70809000,
876
+ slategrey: 0x70809000,
877
+ snow: 0xfffafa00,
878
+ springgreen: 0x00ff7f00,
879
+ steelblue: 0x4682b400,
880
+ tan: 0xd2b48c00,
881
+ teal: 0x00808000,
882
+ thistle: 0xd8bfd800,
883
+ tomato: 0xff634700,
884
+ turquoise: 0x40e0d000,
885
+ violet: 0xee82ee00,
886
+ wheat: 0xf5deb300,
887
+ white: 0xffffff00,
888
+ whitesmoke: 0xf5f5f500,
889
+ yellow: 0xffff0000,
890
+ yellowgreen: 0x9acd3200,
885
891
  }
886
892
 
887
893
  # Gets a color value based on a HTML color name.
@@ -903,14 +909,14 @@ module ChunkyPNG
903
909
  def html_color(color_name, opacity = nil)
904
910
  if color_name.to_s =~ HTML_COLOR_REGEXP
905
911
  opacity ||= $2 ? ($2.to_f * 255.0).round : 0xff
906
- base_color_name = $1.gsub(/[^a-z]+/i, '').downcase.to_sym
907
- return PREDEFINED_COLORS[base_color_name] | opacity if PREDEFINED_COLORS.has_key?(base_color_name)
912
+ base_color_name = $1.gsub(/[^a-z]+/i, "").downcase.to_sym
913
+ return PREDEFINED_COLORS[base_color_name] | opacity if PREDEFINED_COLORS.key?(base_color_name)
908
914
  end
909
915
  raise ArgumentError, "Unknown color name #{color_name}!"
910
916
  end
911
917
 
912
918
  # @return [Integer] Black pixel/color
913
- BLACK = rgb( 0, 0, 0)
919
+ BLACK = rgb(0, 0, 0)
914
920
 
915
921
  # @return [Integer] White pixel/color
916
922
  WHITE = rgb(255, 255, 255)
@@ -927,11 +933,11 @@ module ChunkyPNG
927
933
  # @return [Integer] The number of sample values per pixel.
928
934
  def samples_per_pixel(color_mode)
929
935
  case color_mode
930
- when ChunkyPNG::COLOR_INDEXED; 1
931
- when ChunkyPNG::COLOR_TRUECOLOR; 3
932
- when ChunkyPNG::COLOR_TRUECOLOR_ALPHA; 4
933
- when ChunkyPNG::COLOR_GRAYSCALE; 1
934
- when ChunkyPNG::COLOR_GRAYSCALE_ALPHA; 2
936
+ when ChunkyPNG::COLOR_INDEXED then 1
937
+ when ChunkyPNG::COLOR_TRUECOLOR then 3
938
+ when ChunkyPNG::COLOR_TRUECOLOR_ALPHA then 4
939
+ when ChunkyPNG::COLOR_GRAYSCALE then 1
940
+ when ChunkyPNG::COLOR_GRAYSCALE_ALPHA then 2
935
941
  else raise ChunkyPNG::NotSupported, "Don't know the number of samples for this colormode: #{color_mode}!"
936
942
  end
937
943
  end
@@ -973,7 +979,7 @@ module ChunkyPNG
973
979
  # stored.
974
980
  # @param [Integer] depth The color depth of the pixels.
975
981
  # @param [Integer] width The width of the image pass.
976
- # @param [Integer] width The height of the image pass.
982
+ # @param [Integer] height The height of the image pass.
977
983
  # @return [Integer] The number of bytes used per scanline in a datastream.
978
984
  def pass_bytesize(color_mode, depth, width, height)
979
985
  return 0 if width == 0 || height == 0