chunky_png 1.3.11 → 1.3.12
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.
- checksums.yaml +5 -5
- data/.standard.yml +16 -0
- data/.travis.yml +5 -5
- data/.yardopts +1 -1
- data/CHANGELOG.rdoc +5 -1
- data/CONTRIBUTING.rdoc +17 -8
- data/Gemfile +3 -3
- data/LICENSE +1 -1
- data/README.md +6 -1
- data/Rakefile +3 -3
- data/benchmarks/decoding_benchmark.rb +17 -17
- data/benchmarks/encoding_benchmark.rb +22 -19
- data/benchmarks/filesize_benchmark.rb +6 -6
- data/bin/rake +29 -0
- data/bin/standardrb +29 -0
- data/chunky_png.gemspec +15 -15
- data/lib/chunky_png.rb +16 -25
- data/lib/chunky_png/canvas.rb +28 -27
- data/lib/chunky_png/canvas/adam7_interlacing.rb +14 -10
- data/lib/chunky_png/canvas/data_url_exporting.rb +1 -3
- data/lib/chunky_png/canvas/data_url_importing.rb +1 -3
- data/lib/chunky_png/canvas/drawing.rb +28 -43
- data/lib/chunky_png/canvas/masking.rb +12 -14
- data/lib/chunky_png/canvas/operations.rb +26 -24
- data/lib/chunky_png/canvas/png_decoding.rb +36 -32
- data/lib/chunky_png/canvas/png_encoding.rb +106 -100
- data/lib/chunky_png/canvas/resampling.rb +26 -33
- data/lib/chunky_png/canvas/stream_exporting.rb +6 -8
- data/lib/chunky_png/canvas/stream_importing.rb +6 -8
- data/lib/chunky_png/chunk.rb +69 -60
- data/lib/chunky_png/color.rb +211 -206
- data/lib/chunky_png/datastream.rb +20 -22
- data/lib/chunky_png/dimension.rb +16 -11
- data/lib/chunky_png/image.rb +9 -11
- data/lib/chunky_png/palette.rb +4 -9
- data/lib/chunky_png/point.rb +25 -26
- data/lib/chunky_png/rmagick.rb +8 -10
- data/lib/chunky_png/vector.rb +26 -29
- data/lib/chunky_png/version.rb +1 -1
- data/spec/chunky_png/canvas/adam7_interlacing_spec.rb +20 -21
- data/spec/chunky_png/canvas/data_url_exporting_spec.rb +8 -5
- data/spec/chunky_png/canvas/data_url_importing_spec.rb +5 -6
- data/spec/chunky_png/canvas/drawing_spec.rb +46 -38
- data/spec/chunky_png/canvas/masking_spec.rb +15 -16
- data/spec/chunky_png/canvas/operations_spec.rb +68 -67
- data/spec/chunky_png/canvas/png_decoding_spec.rb +37 -38
- data/spec/chunky_png/canvas/png_encoding_spec.rb +59 -50
- data/spec/chunky_png/canvas/resampling_spec.rb +19 -21
- data/spec/chunky_png/canvas/stream_exporting_spec.rb +47 -27
- data/spec/chunky_png/canvas/stream_importing_spec.rb +10 -11
- data/spec/chunky_png/canvas_spec.rb +57 -52
- data/spec/chunky_png/color_spec.rb +115 -114
- data/spec/chunky_png/datastream_spec.rb +49 -51
- data/spec/chunky_png/dimension_spec.rb +10 -10
- data/spec/chunky_png/image_spec.rb +11 -14
- data/spec/chunky_png/point_spec.rb +21 -23
- data/spec/chunky_png/rmagick_spec.rb +7 -8
- data/spec/chunky_png/vector_spec.rb +21 -17
- data/spec/chunky_png_spec.rb +2 -2
- data/spec/png_suite_spec.rb +35 -40
- data/spec/spec_helper.rb +6 -10
- data/tasks/benchmarks.rake +7 -8
- metadata +34 -5
- data/lib/chunky_png/compatibility.rb +0 -15
data/lib/chunky_png/color.rb
CHANGED
@@ -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
|
35
|
-
when 2
|
36
|
-
when 3
|
37
|
-
when 4
|
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.
|
85
|
+
return source if source.is_a?(Integer)
|
86
86
|
case source.to_s
|
87
|
-
when /^\d
|
88
|
-
when HEX3_COLOR_REGEXP, HEX6_COLOR_REGEXP
|
89
|
-
when HTML_COLOR_REGEXP
|
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]
|
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
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
opacity
|
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).
|
195
|
-
raise ArgumentError, "Saturation must be between 0 and 1" unless (0..1).
|
196
|
-
raise ArgumentError, "Value/brightness must be between 0 and 1" unless (0..1).
|
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
|
-
|
201
|
+
rgba(*rgb)
|
202
202
|
end
|
203
|
-
|
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).
|
219
|
-
raise ArgumentError, "Saturation #{saturation} was not between 0 and 1" unless (0..1).
|
220
|
-
raise ArgumentError, "Lightness #{lightness} was not between 0 and 1" unless (0..1).
|
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
|
-
|
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)
|
255
|
-
when (1...2)
|
256
|
-
when (2...3)
|
257
|
-
when (3...4)
|
258
|
-
when (4...5)
|
259
|
-
when (5..6)
|
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
|
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
|
-
# @
|
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]
|
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 ? (
|
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
|
-
|
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
|
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
|
647
|
-
when g
|
648
|
-
when b
|
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
|
-
|
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
|
-
:
|
739
|
-
:
|
740
|
-
:
|
741
|
-
:
|
742
|
-
:
|
743
|
-
:
|
744
|
-
:
|
745
|
-
:
|
746
|
-
:
|
747
|
-
:
|
748
|
-
:
|
749
|
-
:
|
750
|
-
:
|
751
|
-
:
|
752
|
-
:
|
753
|
-
:
|
754
|
-
:
|
755
|
-
:
|
756
|
-
:
|
757
|
-
:
|
758
|
-
:
|
759
|
-
:
|
760
|
-
:
|
761
|
-
:
|
762
|
-
:
|
763
|
-
:
|
764
|
-
:
|
765
|
-
:
|
766
|
-
:
|
767
|
-
:
|
768
|
-
:
|
769
|
-
:
|
770
|
-
:
|
771
|
-
:
|
772
|
-
:
|
773
|
-
:
|
774
|
-
:
|
775
|
-
:
|
776
|
-
:
|
777
|
-
:
|
778
|
-
:
|
779
|
-
:
|
780
|
-
:
|
781
|
-
:
|
782
|
-
:
|
783
|
-
:
|
784
|
-
:
|
785
|
-
:
|
786
|
-
:
|
787
|
-
:
|
788
|
-
:
|
789
|
-
:
|
790
|
-
:
|
791
|
-
:
|
792
|
-
:
|
793
|
-
:
|
794
|
-
:
|
795
|
-
:
|
796
|
-
:
|
797
|
-
:
|
798
|
-
:
|
799
|
-
:
|
800
|
-
:
|
801
|
-
:
|
802
|
-
:
|
803
|
-
:
|
804
|
-
:
|
805
|
-
:
|
806
|
-
:
|
807
|
-
:
|
808
|
-
:
|
809
|
-
:
|
810
|
-
:
|
811
|
-
:
|
812
|
-
:
|
813
|
-
:
|
814
|
-
:
|
815
|
-
:
|
816
|
-
:
|
817
|
-
:
|
818
|
-
:
|
819
|
-
:
|
820
|
-
:
|
821
|
-
:
|
822
|
-
:
|
823
|
-
:
|
824
|
-
:
|
825
|
-
:
|
826
|
-
:
|
827
|
-
:
|
828
|
-
:
|
829
|
-
:
|
830
|
-
:
|
831
|
-
:
|
832
|
-
:
|
833
|
-
:
|
834
|
-
:
|
835
|
-
:
|
836
|
-
:
|
837
|
-
:
|
838
|
-
:
|
839
|
-
:
|
840
|
-
:
|
841
|
-
:
|
842
|
-
:
|
843
|
-
:
|
844
|
-
:
|
845
|
-
:
|
846
|
-
:
|
847
|
-
:
|
848
|
-
:
|
849
|
-
:
|
850
|
-
:
|
851
|
-
:
|
852
|
-
:
|
853
|
-
:
|
854
|
-
:
|
855
|
-
:
|
856
|
-
:
|
857
|
-
:
|
858
|
-
:
|
859
|
-
:
|
860
|
-
:
|
861
|
-
:
|
862
|
-
:
|
863
|
-
:
|
864
|
-
:
|
865
|
-
:
|
866
|
-
:
|
867
|
-
:
|
868
|
-
:
|
869
|
-
:
|
870
|
-
:
|
871
|
-
:
|
872
|
-
:
|
873
|
-
:
|
874
|
-
:
|
875
|
-
:
|
876
|
-
:
|
877
|
-
:
|
878
|
-
:
|
879
|
-
:
|
880
|
-
:
|
881
|
-
:
|
882
|
-
:
|
883
|
-
:
|
884
|
-
:
|
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,
|
907
|
-
return PREDEFINED_COLORS[base_color_name] | opacity if PREDEFINED_COLORS.
|
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(
|
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
|
931
|
-
when ChunkyPNG::COLOR_TRUECOLOR
|
932
|
-
when ChunkyPNG::COLOR_TRUECOLOR_ALPHA
|
933
|
-
when ChunkyPNG::COLOR_GRAYSCALE
|
934
|
-
when ChunkyPNG::COLOR_GRAYSCALE_ALPHA
|
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]
|
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
|