Class: SVGProfiler::Histogram
- Inherits:
-
Object
- Object
- SVGProfiler::Histogram
- Defined in:
- lib/svg_profiler/histogram.rb
Constant Summary collapse
- WARN_THRESHOLD =
0.02
Class Method Summary collapse
Instance Method Summary collapse
- #histogram ⇒ Object
-
#initialize(xml_string, png) ⇒ Histogram
constructor
A new instance of Histogram.
Constructor Details
#initialize(xml_string, png) ⇒ Histogram
Returns a new instance of Histogram.
9 10 11 12 13 |
# File 'lib/svg_profiler/histogram.rb', line 9 def initialize(xml_string, png) check_for_imagemagick @image = Magick::Image.read(png.path).first @palette = SVGPalette.parse(xml_string) end |
Class Method Details
.for(xml_string, png) ⇒ Object
5 6 7 |
# File 'lib/svg_profiler/histogram.rb', line 5 def self.for(xml_string, png) new(xml_string, png).histogram end |
Instance Method Details
#histogram ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/svg_profiler/histogram.rb', line 15 def histogram @image.quantize(8) # 00-FF is 8-bits. histogram = @image.color_histogram frequencies = histogram.inject({}) do |hash, (p, f)| hash.merge(to_hex(p) => f) end filter_by_palette!(frequencies) normalize(frequencies) end |