chunky_png 1.3.10 → 1.3.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ruby.yml +35 -0
- data/.standard.yml +16 -0
- data/.yardopts +1 -1
- data/CHANGELOG.rdoc +8 -4
- data/CONTRIBUTING.rdoc +17 -8
- data/Gemfile +12 -4
- data/LICENSE +1 -1
- data/README.md +15 -9
- data/Rakefile +5 -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 +21 -13
- data/docs/.gitignore +3 -0
- data/docs/CNAME +1 -0
- data/docs/_config.yml +9 -0
- data/docs/_posts/2010-01-14-memory-efficiency-when-using-ruby.md +136 -0
- data/docs/_posts/2010-01-17-ode-to-array-pack-and-string-unpack.md +82 -0
- data/docs/_posts/2014-11-07-the-value-of-a-pure-ruby-library.md +61 -0
- data/docs/index.md +88 -0
- data/lib/chunky_png.rb +17 -30
- data/lib/chunky_png/canvas.rb +31 -28
- data/lib/chunky_png/canvas/adam7_interlacing.rb +16 -10
- data/lib/chunky_png/canvas/data_url_exporting.rb +3 -3
- data/lib/chunky_png/canvas/data_url_importing.rb +3 -3
- data/lib/chunky_png/canvas/drawing.rb +30 -43
- data/lib/chunky_png/canvas/masking.rb +14 -14
- data/lib/chunky_png/canvas/operations.rb +28 -24
- data/lib/chunky_png/canvas/png_decoding.rb +39 -33
- data/lib/chunky_png/canvas/png_encoding.rb +111 -103
- data/lib/chunky_png/canvas/resampling.rb +27 -32
- data/lib/chunky_png/canvas/stream_exporting.rb +8 -8
- data/lib/chunky_png/canvas/stream_importing.rb +8 -8
- data/lib/chunky_png/chunk.rb +101 -66
- data/lib/chunky_png/color.rb +218 -212
- data/lib/chunky_png/datastream.rb +23 -29
- data/lib/chunky_png/dimension.rb +18 -11
- data/lib/chunky_png/image.rb +11 -11
- data/lib/chunky_png/palette.rb +13 -14
- data/lib/chunky_png/point.rb +27 -26
- data/lib/chunky_png/rmagick.rb +10 -10
- data/lib/chunky_png/vector.rb +28 -29
- data/lib/chunky_png/version.rb +3 -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 +63 -52
- data/spec/chunky_png/color_spec.rb +115 -114
- data/spec/chunky_png/datastream_spec.rb +55 -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 +51 -13
- data/.travis.yml +0 -16
- data/lib/chunky_png/compatibility.rb +0 -15
data/lib/chunky_png/color.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
|
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
|
35
|
-
when 2
|
36
|
-
when 3
|
37
|
-
when 4
|
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.
|
87
|
+
return source if source.is_a?(Integer)
|
86
88
|
case source.to_s
|
87
|
-
when /^\d
|
88
|
-
when HEX3_COLOR_REGEXP, HEX6_COLOR_REGEXP
|
89
|
-
when HTML_COLOR_REGEXP
|
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]
|
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
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
opacity
|
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
|
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).
|
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).
|
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
|
-
|
203
|
+
rgba(*rgb)
|
202
204
|
end
|
203
|
-
|
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
|
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).
|
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).
|
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
|
-
|
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
|
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)
|
255
|
-
when (1...2)
|
256
|
-
when (2...3)
|
257
|
-
when (3...4)
|
258
|
-
when (4...5)
|
259
|
-
when (5..6)
|
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
|
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
|
-
# @
|
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]
|
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 ? (
|
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
|
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
|
-
|
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
|
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
|
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
|
647
|
-
when g
|
648
|
-
when b
|
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
|
-
|
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
|
-
:
|
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
|
-
:
|
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,
|
907
|
-
return PREDEFINED_COLORS[base_color_name] | opacity if PREDEFINED_COLORS.
|
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(
|
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
|
931
|
-
when ChunkyPNG::COLOR_TRUECOLOR
|
932
|
-
when ChunkyPNG::COLOR_TRUECOLOR_ALPHA
|
933
|
-
when ChunkyPNG::COLOR_GRAYSCALE
|
934
|
-
when ChunkyPNG::COLOR_GRAYSCALE_ALPHA
|
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]
|
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
|