Sha256: 5a955d60a3128155ae56c2a404c051e5241dadd6413f6fe791995210486b7deb

Contents?: true

Size: 610 Bytes

Versions: 1

Compression:

Stored size: 610 Bytes

Contents

# frozen_string_literal: true

module Camalian
  module Quantization
    class Histogram # :nodoc:
      def process(colors, count)
        bucket_size = (255.0 / count).ceil
        buckets = {}

        colors.each do |color|
          key = bucket_key(color, bucket_size)
          buckets[key] ||= Palette.new
          buckets[key].push(color)
        end

        Palette.new(buckets.map { |_, value| value.average_color })
      end

      private

      def bucket_key(color, bucket_size)
        "#{color.r / bucket_size}:#{color.g / bucket_size}:#{color.b / bucket_size}"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
camalian-0.1.0 lib/camalian/quantization/histogram.rb