chunky_png 1.3.7 → 1.3.12

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