[
  {
    "path": ".gitignore",
    "content": "/.bundle/\n/.yardoc\n/Gemfile.lock\n/_yardoc/\n/coverage/\n/doc/\n/pkg/\n/spec/reports/\n/tmp/\n*.bundle\n*.so\n*.o\n*.a\nmkmf.log\n.DS_Store\n"
  },
  {
    "path": ".rspec",
    "content": "--color\n--format documentation\n\n"
  },
  {
    "path": ".travis.yml",
    "content": "language: ruby\nscript:\n  - CODECLIMATE_REPO_TOKEN=edbf400c9cd2e92ef8eabf2dad1d03b0ed0cb2a83a20f12f70e4f8107c38de51 bundle exec rake\nrvm:\n  - 2.1\nnotifications:\n  email:\n    - anna.slimak@lunarlogic.io\n\n"
  },
  {
    "path": "Gemfile",
    "content": "source 'https://rubygems.org'\n\n# Specify your gem's dependencies in gauguin.gemspec\ngemspec\n"
  },
  {
    "path": "Guardfile",
    "content": "guard :rspec, cmd: 'bundle exec rspec' do\n  watch(%r{^spec/.+_spec\\.rb$})\n  watch(%r{^lib/(.+)\\.rb$})     { |m| \"spec/lib/#{m[1]}_spec.rb\" }\n  watch('spec/spec_helper.rb')  { \"spec\" }\nend\n\n"
  },
  {
    "path": "LICENSE.txt",
    "content": "Copyright (c) 2014 Lunar Logic Polska http://lunarlogicpolska.com\n\nMIT License\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\nLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\nOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\nWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "[![Build Status](https://travis-ci.org/LunarLogic/gauguin.svg?branch=master)](https://travis-ci.org/LunarLogic/gauguin)\n[![Code Climate](https://codeclimate.com/github/LunarLogic/gauguin/badges/gpa.svg)](https://codeclimate.com/github/LunarLogic/gauguin)\n[![Test Coverage](https://codeclimate.com/github/LunarLogic/gauguin/badges/coverage.svg)](https://codeclimate.com/github/LunarLogic/gauguin)\n\n<img src=\"http://gauguin.lunarlogic.io/assets/gauguin-b7a7737e8ede819b98df9d05f7df020a.png\" alt=\"Guard Icon\" align=\"left\" />\n# Gauguin\n\nRetrieves palette of main colors, merging similar colors using [Lab color space](http://en.wikipedia.org/wiki/Lab_color_space).\n\n## Why not just use `RMagick`?\n\nHow many colors do you recognize on the image below?\n\n![Black and white image](http://gauguin.lunarlogic.io/assets/gray_and_black-b6871d86ef45c8740bf898233b0a588c.png)\n\nMany people would say `2`, but actually there are `1942`.\n\nIt's because of the fact that to make image more smooth, borders of the figure are not pure black but consist of many gray scale colors.\n\nIt's common that images includes very similar colors, so when you want to get useful color palette, you would need to process color histogram you get from `RMagick` yourself.\n\nThis gem was created to do this for you.\n\n## Sample app\n\nSample application available here: http://gauguin.lunarlogic.io\n\n## Requirements\n\nGem depends on `RMagick` which requires `ImageMagick` to be installed.\n\n### Ubuntu\n\n    $ sudo apt-get install imagemagick\n\n### OSX\n\n    $ brew install imagemagick\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'gauguin'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install gauguin\n\n## Usage\n\n#### Palette\n\n```ruby\npalette = Gauguin::Painting.new(\"path/to/image.png\").palette\n```\n\nResult for image above would be:\n\n```ruby\n  {\n    rgb(204, 204, 204)[0.5900935269505287] => [\n      rgb(77, 77, 77)[7.383706620723603e-05],\n      rgb(85, 85, 85)[0.00012306177701206005],\n      # ...\n      rgb(219, 220, 219)[1.2306177701206005e-05],\n      rgb(220, 220, 220)[7.383706620723603e-05]\n    ],\n    rgb(0, 0, 0)[0.40990647304947003] => [\n      rgb(0, 0, 0)[0.40990647304947003],\n      rgb(1, 1, 1)[0.007912872261875462],\n      # ...\n      rgb(64, 64, 64)[6.153088850603002e-05],\n      rgb(66, 66, 66)[6.153088850603002e-05]\n    ]\n  }\n```\n\nWhere keys are instances of `Gauguin::Color` class and values are array of instances of `Gauguin::Color` class.\n\n#### Recolor\n\nThere is also recolor feature - you can pass original image and the calculated palette and return new image, colored only with the main colours from the palette.\n\n```ruby\npainting.recolor(palette, 'path/where/recolored/file/will/be/placed')\n```\n\n## Custom configuration\n\nThere are `4` parameters that you can configure:\n\n- `max_colors_count` (default value is `10`) - maximum number of colors that a palette will include\n- `colors_limit` (default value is `10000`) - maximum number of colors that will be considered while calculating a palette - if image has too many colors it is not efficient to calculate grouping for all of them, so only `colors_limit` of colors of the largest percentage are used\n- `min_percentage_sum` (default value is `0.981`) - parameter used while calculating which colors should be ignored. Colors are sorted by percentage in descending order, then colors which percentages sums to `min_percentage_sum` are taken into consideration\n- `color_similarity_threshold` (default value is `25`) - maximum distance in [Lab color space](http://en.wikipedia.org/wiki/Lab_color_space) to consider two colors as the same while grouping\n\nTo configure any of above options you can use configuration block.\nFor example changing `max_colors_count` would look like this:\n\n```ruby\nGauguin.configuration do |config|\n  config.max_colors_count = 7\nend\n```\n\n## Contributing\n\n1. Fork it ( https://github.com/LunarLogic/gauguin/fork )\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n"
  },
  {
    "path": "Rakefile",
    "content": "require \"bundler/gem_tasks\"\n\nrequire 'rake'\nrequire 'rspec/core/rake_task'\n\ndesc \"Run all examples\"\nRSpec::Core::RakeTask.new(:spec) do |t|\n  t.rspec_opts = %w[--color]\nend\n\n\ntask :default => [:spec]\n\n"
  },
  {
    "path": "gauguin.gemspec",
    "content": "# coding: utf-8\nlib = File.expand_path('../lib', __FILE__)\n$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)\nrequire 'gauguin/version'\n\nGem::Specification.new do |spec|\n  spec.name          = \"gauguin\"\n  spec.version       = Gauguin::VERSION\n  spec.authors       = [\"Ania Slimak\"]\n  spec.email         = [\"anna.slimak@lunarlogic.io\"]\n  spec.summary       = %q{Tool for retrieving main colors from the image.}\n  spec.description   = %q{Retrieves palette of main colors, merging similar colors using Lab color space.}\n  spec.homepage      = \"https://github.com/LunarLogic/gauguin\"\n  spec.license       = \"MIT\"\n\n  spec.files         = `git ls-files -z`.split(\"\\x0\")\n  spec.executables   = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }\n  spec.test_files    = spec.files.grep(%r{^(test|spec|features)/})\n  spec.require_paths = [\"lib\"]\n\n  spec.add_dependency \"rmagick\"\n\n  spec.add_development_dependency \"bundler\", \"~> 1.7\"\n  spec.add_development_dependency \"rake\", \"~> 10.0\"\n  spec.add_development_dependency \"rspec\", \"~> 3.2\"\n  spec.add_development_dependency \"simplecov\"\n  spec.add_development_dependency \"codeclimate-test-reporter\"\n  spec.add_development_dependency \"guard-rspec\"\n  spec.add_development_dependency \"pry\"\nend\n"
  },
  {
    "path": "lib/gauguin/color.rb",
    "content": "module Gauguin\n  class Color\n    attr_accessor :red, :green, :blue, :percentage, :transparent\n\n    def initialize(red, green, blue, percentage = 1, transparent = false)\n      self.red = red\n      self.green = green\n      self.blue = blue\n      self.percentage = percentage\n      self.transparent = transparent\n    end\n\n    def ==(other)\n      self.class == other.class && self.to_key == other.to_key\n    end\n\n    alias eql? ==\n\n    def hash\n      self.to_key.hash\n    end\n\n    def similar?(other_color)\n      self.transparent == other_color.transparent &&\n        self.distance(other_color) < Gauguin.configuration.color_similarity_threshold\n    end\n\n    def distance(other_color)\n      (self.to_lab - other_color.to_lab).r\n    end\n\n    def to_lab\n      rgb_vector = self.to_vector\n      xyz_vector = rgb_vector.to_xyz\n      xyz_vector.to_lab\n    end\n\n    def to_vector\n      ColorSpace::RgbVector[*to_rgb]\n    end\n\n    def to_rgb\n      [self.red, self.green, self.blue]\n    end\n\n    def to_a\n      to_rgb + [self.percentage, self.transparent]\n    end\n\n    def self.from_a(array)\n      red, green, blue, percentage, transparent = array\n      Color.new(red, green, blue, percentage, transparent)\n    end\n\n    def to_key\n      to_rgb + [self.transparent]\n    end\n\n    def to_s\n      \"rgb(#{self.red}, #{self.green}, #{self.blue})\"\n    end\n\n    def inspect\n      msg = \"#{to_s}[#{percentage}]\"\n      if transparent?\n        msg += \"[transparent]\"\n      end\n      msg\n    end\n\n    def transparent?\n      self.transparent\n    end\n  end\nend\n\n"
  },
  {
    "path": "lib/gauguin/color_space/lab_vector.rb",
    "content": "module Gauguin\n  module ColorSpace\n    class LabVector < Vector\n    end\n  end\nend\n"
  },
  {
    "path": "lib/gauguin/color_space/rgb_vector.rb",
    "content": "module Gauguin\n  module ColorSpace\n    class RgbVector < Vector\n      MAX_VAUE = 255.0\n\n      # Observer. = 2°, Illuminant = D65\n      RGB_TO_XYZ = Matrix[[0.4124, 0.2126, 0.0193],\n                          [0.3576, 0.7152, 0.1192],\n                          [0.1805, 0.0722, 0.9505]]\n\n      def pivot!\n        self.each.with_index do |component, i|\n          self[i] = pivot(component / MAX_VAUE)\n        end\n        self\n      end\n\n      def to_xyz\n        self.pivot!\n        matrix = Matrix[self] * RGB_TO_XYZ\n        XyzVector[*matrix.row_vectors.first.to_a]\n      end\n\n      private\n\n      def pivot(component)\n        component = if component > 0.04045\n          ((component + 0.055) / 1.055) ** 2.4\n        else\n          component / 12.92\n        end\n        component * 100.0\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/gauguin/color_space/xyz_vector.rb",
    "content": "module Gauguin\n  module ColorSpace\n    class XyzVector < Vector\n      WHITE_REFERENCE = self[95.047, 100.000, 108.883]\n\n      EPSILON = 0.008856\n      KAPPA = 903.3\n\n      def to_lab\n        zipped = self.zip(XyzVector::WHITE_REFERENCE)\n        x, y, z = zipped.map do |component, white_component|\n          component / white_component\n        end\n\n        l = 116 * f(y) - 16\n        a = 500 * (f(x) - f(y))\n        b = 200 * (f(y) - f(z))\n\n        LabVector[l, a, b]\n      end\n\n      private\n\n      def f(x)\n        if x > EPSILON\n          x ** (1.0/3.0)\n        else\n          (KAPPA * x + 16.0) / 116.0\n        end\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/gauguin/color_space.rb",
    "content": "require 'matrix'\nrequire \"gauguin/color_space/rgb_vector\"\nrequire \"gauguin/color_space/xyz_vector\"\nrequire \"gauguin/color_space/lab_vector\"\n"
  },
  {
    "path": "lib/gauguin/colors_clusterer.rb",
    "content": "module Gauguin\n  class ColorsClusterer\n    def call(colors)\n      clusters = {}\n\n      while !colors.empty?\n        pivot = colors.shift\n        group = [pivot]\n\n        colors, pivot, group = find_all_similar(colors, pivot, group)\n\n        clusters[pivot] = group\n      end\n\n      update_pivots_percentages(clusters)\n\n      clusters\n    end\n\n    def clusters(colors)\n      clusters = self.call(colors)\n      clusters = clusters.sort_by { |color, _| color.percentage }.reverse\n      Hash[clusters[0...Gauguin.configuration.max_colors_count]]\n    end\n\n    def reversed_clusters(clusters)\n      reversed_clusters = {}\n\n      clusters.each do |pivot, group|\n        group.each do |color|\n          reversed_clusters[color] = pivot\n        end\n      end\n\n      reversed_clusters\n    end\n\n    private\n\n    def find_all_similar(colors, pivot, group)\n      loop do\n        similar_colors = colors.select { |c| c.similar?(pivot) }\n        break if similar_colors.empty?\n\n        group += similar_colors\n        colors -= similar_colors\n\n        pivot = group.sort_by(&:percentage).last\n      end\n\n      [colors, pivot, group]\n    end\n\n    def update_pivots_percentages(clusters)\n      clusters.each do |main_color, group|\n        percentage = group.inject(0) do |sum, color|\n          sum += color.percentage\n        end\n        main_color.percentage = percentage\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/gauguin/colors_limiter.rb",
    "content": "module Gauguin\n  class ColorsLimiter\n    def call(colors)\n      colors_limit = Gauguin.configuration.colors_limit\n\n      if colors.count > colors_limit\n        colors = colors.sort_by { |key, group| key.percentage }.\n          reverse[0..colors_limit - 1]\n      end\n\n      colors\n    end\n  end\nend\n"
  },
  {
    "path": "lib/gauguin/colors_retriever.rb",
    "content": "module Gauguin\n  class ColorsRetriever\n    def initialize(image)\n      @image = image\n    end\n\n    def colors\n      colors = {}\n\n      histogram = @image.color_histogram\n      image_size = @image.columns * @image.rows\n\n      histogram.each do |pixel, count|\n        image_pixel = @image.pixel(pixel)\n\n        red, green, blue = image_pixel.to_rgb\n        percentage = count.to_f / image_size\n        color = Gauguin::Color.new(red, green, blue, percentage,\n                                   image_pixel.transparent?)\n\n        # histogram can contain different magic pixels for\n        # the same colors with different opacity\n        if colors[color]\n          colors[color].percentage += color.percentage\n        else\n          colors[color] = color\n        end\n      end\n\n      colors.values\n    end\n  end\nend\n"
  },
  {
    "path": "lib/gauguin/image.rb",
    "content": "require 'rmagick'\nrequire 'forwardable'\n\nmodule Gauguin\n  class Image\n    extend Forwardable\n    attr_accessor :image\n    delegate [:color_histogram, :columns, :rows, :write] => :image\n\n    def initialize(path = nil)\n      return unless path\n\n      list = Magick::ImageList.new(path)\n      self.image = list.first\n    end\n\n    def self.blank(columns, rows)\n      blank_image = Image.new\n      transparent_white = Magick::Pixel.new(255, 255, 255, Pixel::MAX_TRANSPARENCY)\n      blank_image.image = Magick::Image.new(columns, rows) do\n        self.background_color = transparent_white\n      end\n      blank_image\n    end\n\n    def pixel(magic_pixel)\n      Pixel.new(magic_pixel)\n    end\n\n    def pixel_color(row, column, *args)\n      magic_pixel = self.image.pixel_color(row, column, *args)\n      pixel(magic_pixel)\n    end\n\n    class Pixel\n      MAX_CHANNEL_VALUE = 257\n      MAX_TRANSPARENCY = 65535\n\n      def initialize(magic_pixel)\n        @magic_pixel = magic_pixel\n      end\n\n      def transparent?\n        @magic_pixel.opacity >= MAX_TRANSPARENCY\n      end\n\n      def to_rgb\n        [:red, :green, :blue].map do |color|\n          @magic_pixel.send(color) / MAX_CHANNEL_VALUE\n        end\n      end\n    end\n  end\nend\n\n"
  },
  {
    "path": "lib/gauguin/image_recolorer.rb",
    "content": "module Gauguin\n  class ImageRecolorer\n    def initialize(image)\n      @image = image.dup\n    end\n\n    def recolor(new_colors)\n      columns = @image.columns\n      rows = @image.rows\n\n      new_image = Image.blank(columns, rows)\n\n      (0...columns).each do |column|\n        (0...rows).each do |row|\n          image_pixel = @image.pixel_color(column, row)\n          next if image_pixel.transparent?\n\n          color = Color.new(*image_pixel.to_rgb)\n          new_color = new_colors[color]\n\n          next unless new_color\n\n          new_image.pixel_color(column, row, new_color.to_s)\n        end\n      end\n      new_image\n    end\n  end\nend\n"
  },
  {
    "path": "lib/gauguin/image_repository.rb",
    "content": "module Gauguin\n  class ImageRepository\n    def get(path)\n      Gauguin::Image.new(path)\n    end\n  end\nend\n"
  },
  {
    "path": "lib/gauguin/noise_reducer.rb",
    "content": "module Gauguin\n  class NoiseReducer\n    def call(colors_clusters)\n      pivots = colors_clusters.keys.sort_by! { |key, group| key.percentage }.reverse\n\n      percentage_sum = 0\n      index = 0\n      pivots.each do |color|\n        percentage_sum += color.percentage\n        break if percentage_sum > Gauguin.configuration.min_percentage_sum\n        index += 1\n      end\n\n      reduced_clusters(colors_clusters, pivots, index)\n    end\n\n    private\n\n    def reduced_clusters(colors_clusters, pivots, cut_off_index)\n      reduced_pivots = pivots[0..cut_off_index]\n      colors_clusters.select do |c|\n        !c.transparent? && reduced_pivots.include?(c)\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/gauguin/painting.rb",
    "content": "module Gauguin\n  class Painting\n    def initialize(path, image_repository = nil, colors_retriever = nil,\n                   colors_limiter = nil, noise_reducer = nil,\n                   colors_clusterer = nil, image_recolorer = nil)\n      @image_repository = image_repository || Gauguin::ImageRepository.new\n      @image = @image_repository.get(path)\n      @colors_retriever = colors_retriever || Gauguin::ColorsRetriever.new(@image)\n      @colors_limiter = colors_limiter || Gauguin::ColorsLimiter.new\n      @noise_reducer = noise_reducer || Gauguin::NoiseReducer.new\n      @colors_clusterer = colors_clusterer || Gauguin::ColorsClusterer.new\n      @image_recolorer = image_recolorer || Gauguin::ImageRecolorer.new(@image)\n    end\n\n    def palette\n      colors = @colors_retriever.colors\n      colors = @colors_limiter.call(colors)\n      colors_clusters = @colors_clusterer.clusters(colors)\n      @noise_reducer.call(colors_clusters)\n    end\n\n    def recolor(palette, path)\n      new_colors = @colors_clusterer.reversed_clusters(palette)\n      recolored_image = @image_recolorer.recolor(new_colors)\n      recolored_image.write(path)\n    end\n  end\nend\n\n"
  },
  {
    "path": "lib/gauguin/palette_serializer.rb",
    "content": "require 'yaml'\n\nmodule Gauguin\n  class PaletteSerializer\n    def self.load(value)\n      return unless value\n\n      value = YAML.load(value)\n      value = value.to_a.map do |color_key, group|\n        [Gauguin::Color.from_a(color_key), group]\n      end\n      Hash[value]\n    end\n\n    def self.dump(value)\n      value = value.to_a.map { |color, group| [color.to_a, group] }\n      value = Hash[value]\n      YAML.dump(value)\n    end\n  end\nend\n\n"
  },
  {
    "path": "lib/gauguin/version.rb",
    "content": "module Gauguin\n  VERSION = \"0.0.3\"\nend\n"
  },
  {
    "path": "lib/gauguin.rb",
    "content": "require \"gauguin/version\"\nrequire \"gauguin/color\"\nrequire \"gauguin/color_space\"\nrequire \"gauguin/colors_retriever\"\nrequire \"gauguin/colors_limiter\"\nrequire \"gauguin/colors_clusterer\"\nrequire \"gauguin/noise_reducer\"\nrequire \"gauguin/image_recolorer\"\nrequire \"gauguin/painting\"\nrequire \"gauguin/image\"\nrequire \"gauguin/image_repository\"\nrequire \"gauguin/palette_serializer\"\n\nmodule Gauguin\n  class << self\n    attr_accessor :configuration\n  end\n\n  def self.configure\n    self.configuration ||= Configuration.new\n    yield(configuration) if block_given?\n  end\n\n  class Configuration\n    DEFAULT_MAX_COLORS_COUNT = 10\n    DEFAULT_COLORS_LIMIT = 10000\n    DEFAULT_MIN_PERCENTAGE_SUM = 0.981\n    DEFAULT_COLOR_SIMILARITY_THRESHOLD = 25\n\n    attr_accessor :max_colors_count, :colors_limit,\n      :min_percentage_sum, :color_similarity_threshold\n\n    def initialize\n      @max_colors_count = DEFAULT_MAX_COLORS_COUNT\n      @colors_limit = DEFAULT_COLORS_LIMIT\n      @min_percentage_sum = DEFAULT_MIN_PERCENTAGE_SUM\n      @color_similarity_threshold = DEFAULT_COLOR_SIMILARITY_THRESHOLD\n    end\n  end\nend\n\nGauguin.configure\n\n"
  },
  {
    "path": "spec/integration/painting_spec.rb",
    "content": "require 'spec_helper'\n\nmodule Gauguin\n  describe Painting do\n    let(:path) do\n      File.join(\"spec\", \"support\", \"pictures\", file_name)\n    end\n\n    let(:gray) { Color.new(204, 204, 204) }\n    let(:black) { Color.new(0, 0, 0) }\n    let(:white) { Color.new(255, 255, 255) }\n\n    let(:painting) { Painting.new(path) }\n\n    describe \"#palette\" do\n      shared_examples_for \"retrieves unique colors\" do\n        it { expect(subject.count).to eq 5 }\n        it do\n          expect(subject.keys).to include(white)\n        end\n      end\n\n      subject { painting.palette }\n\n      context \"unique colors in the picture\" do\n        let(:file_name) { \"unique_colors.png\" }\n\n        it_behaves_like \"retrieves unique colors\"\n      end\n\n      context \"not unique colors in the picture\" do\n        let(:file_name) { \"not_unique_colors.png\" }\n\n        it_behaves_like \"retrieves unique colors\"\n      end\n\n      context \"image has two colors but with different gradients\n        so actually 1942 unique colors\" do\n        let(:file_name) { \"gray_and_black.png\" }\n        let(:values) { subject.values.flatten }\n\n        it { expect(subject.count).to eq 2 }\n        it { expect(values.include?(black)).to be true }\n        it { expect(values.include?(gray)).to be true }\n      end\n\n      context \"transparent background\" do\n        let(:file_name) { \"transparent_background.png\" }\n\n        it { expect(subject.count).to eq 1 }\n        it do\n          expect(subject.keys).to eq [Color.new(2, 0, 0)]\n        end\n      end\n\n      context \"image with 10 colors\" do\n        let(:file_name) { \"10_colors.png\" }\n\n        it { expect(subject.count).to eq 10 }\n      end\n\n      context \"image with over than max_colors_count colors\" do\n        let(:file_name) { \"12_colors.png\" }\n\n        it { expect(subject.count).to eq 10 }\n\n        context \"image with over than colors_limit colors\" do\n          configure(:colors_limit, 9)\n          configure(:max_colors_count, 12)\n\n          it \"returns colors_limit colors\" do\n            expect(subject.count).to eq 9\n          end\n        end\n      end\n    end\n  end\nend\n\n"
  },
  {
    "path": "spec/integration/samples_spec.rb",
    "content": "require 'spec_helper'\n\nmodule Gauguin\n  describe \"samples\" do\n    def self.picture_path(file_name)\n      File.join(\"spec\", \"support\", \"pictures\", file_name)\n    end\n\n    let(:painting) { Painting.new(picture_path(file_name)) }\n\n    def self.paths\n      (1..11).map { |i| picture_path(File.join(\"samples\", \"sample#{i}.png\")) }\n    end\n\n    def self.expected_results\n      [\n        [\"rgb(219, 12, 38)\", \"rgb(255, 255, 255)\"],\n        [\"rgb(168, 36, 40)\", \"rgb(255, 255, 255)\"],\n        [\"rgb(0, 0, 0)\", \"rgb(204, 204, 204)\"],\n        [\"rgb(154, 79, 54)\", \"rgb(187, 196, 201)\", \"rgb(236, 112, 48)\", \"rgb(28, 28, 64)\", \"rgb(92, 54, 59)\"],\n        [\"rgb(254, 254, 254)\", \"rgb(255, 195, 13)\", \"rgb(60, 4, 67)\"],\n        [\"rgb(2, 0, 0)\"],\n        [\"rgb(148, 158, 149)\", \"rgb(198, 64, 63)\"],\n        [\"rgb(109, 207, 246)\", \"rgb(237, 28, 36)\", \"rgb(255, 255, 255)\"],\n        [\"rgb(255, 255, 255)\", \"rgb(87, 196, 15)\"],\n        [\"rgb(240, 110, 170)\", \"rgb(255, 255, 255)\"],\n        [\"rgb(0, 165, 19)\", \"rgb(0, 71, 241)\", \"rgb(230, 27, 49)\", \"rgb(249, 166, 0)\", \"rgb(255, 255, 255)\"]\n      ]\n    end\n\n    def self.samples\n      Hash[paths.zip(expected_results)]\n    end\n\n    samples.each do |sample_path, expected_result|\n      it \"returns expected result for #{sample_path}\" do\n        painting = Painting.new(sample_path)\n        expect(painting.palette.keys.map(&:to_s).sort).to eq(expected_result.sort)\n      end\n    end\n  end\nend\n\n"
  },
  {
    "path": "spec/lib/gauguin/color_space/rgb_vector_spec.rb",
    "content": "require 'spec_helper'\n\nmodule Gauguin::ColorSpace\n  describe RgbVector do\n    describe \"#to_xyz\" do\n      let(:red) { RgbVector[255, 0, 0] }\n\n      it \"converts to lab space\" do\n        expect(red.to_xyz).to eq(\n          XyzVector[41.24, 21.26, 1.9300000000000002])\n      end\n    end\n  end\nend\n\n"
  },
  {
    "path": "spec/lib/gauguin/color_space/xyz_vector_spec.rb",
    "content": "require 'spec_helper'\n\nmodule Gauguin::ColorSpace\n  describe XyzVector do\n    describe \"#to_lab\" do\n      let(:red) { XyzVector[41.24, 21.26, 1.9300000000000002] }\n\n      it \"converts to lab space\" do\n        expect(red.to_lab).to eq(\n          LabVector[53.23288178584245, 80.10930952982204, 67.22006831026425])\n      end\n    end\n  end\nend\n\n"
  },
  {
    "path": "spec/lib/gauguin/color_spec.rb",
    "content": "require 'spec_helper'\n\nmodule Gauguin\n  describe Color do\n    let(:black) { Color.new(0, 0, 0) }\n    let(:red) { Color.new(255, 0, 0) }\n\n    describe \"initialize\" do\n      let(:red) { 1 }\n      let(:green) { 2 }\n      let(:blue) { 3 }\n      let(:percentage) { 0.5 }\n\n      subject { Color.new(red, green, blue, percentage) }\n\n      it { expect(subject.red).to eq red }\n      it { expect(subject.green).to eq green }\n      it { expect(subject.blue).to eq blue }\n      it { expect(subject.percentage).to eq percentage }\n    end\n\n    describe \"#==\" do\n      it \"returns true for colors with the same key values\" do\n        expect(black == Color.new(0, 0, 0)).to be true\n      end\n\n      it \"returns false if any key value is different\" do\n        expect(black == Color.new(0, 0, 1)).to be false\n      end\n\n      it \"returns false for objects with different classes\" do\n        expect(black == \"black\").to be false\n      end\n    end\n\n    describe \"#similar?\" do\n      context \"similar colors\" do\n        it { expect(black.similar?(Color.new(0, 0, 1))).to be true }\n      end\n\n      context \"different colors\" do\n        it { expect(black.similar?(red)).to be false }\n      end\n    end\n\n    describe '#distance' do\n      it 'returns circa 178.36 between black & red' do\n        expect(black.distance(red)).to be_within(0.01).of(117.34)\n      end\n    end\n\n    describe \"#to_lab\" do\n      let(:red) { 1 }\n      let(:green) { 2 }\n      let(:blue) { 3 }\n\n      subject { Color.new(red, green, blue).to_lab }\n\n      it \"returns lab vector\" do\n        rgb_vector = double\n        xyz_vector = double\n        expect(ColorSpace::RgbVector).to receive(:[]).with(red, green, blue).and_return(rgb_vector)\n        expect(rgb_vector).to receive(:to_xyz).and_return(xyz_vector)\n        expect(xyz_vector).to receive(:to_lab)\n\n        subject\n      end\n    end\n\n    describe \"#to_s\" do\n      subject { black.to_s }\n\n      it { expect(subject).to eq(\"rgb(0, 0, 0)\") }\n    end\n\n    let(:color) { Color.new(1, 2, 3, 0.4, true) }\n\n    describe \"#to_rgb\" do\n      subject { color.to_rgb }\n\n      it { expect(subject).to eq([1, 2, 3]) }\n    end\n\n    describe \"#to_key\" do\n      subject { color.to_key }\n\n      it { expect(subject).to eq([1, 2, 3, true]) }\n    end\n\n    describe \"#to_a\" do\n      subject { color.to_a }\n\n      it { expect(subject).to eq([1, 2, 3, 0.4, true]) }\n    end\n\n    describe \".from_a\" do\n      subject { Color.from_a([1, 2, 3, 0.4, true]) }\n\n      it { expect(subject.red).to eq(1) }\n      it { expect(subject.green).to eq(2) }\n      it { expect(subject.blue).to eq(3) }\n      it { expect(subject.percentage).to eq(0.4) }\n      it { expect(subject.transparent).to be true }\n    end\n\n    describe \"#transparent?\" do\n      subject { color.transparent? }\n\n      it { expect(subject).to be true }\n    end\n\n    describe \"#hash\" do\n      it \"can be used as keys in the hash\"  do\n        hash = { Color.new(255, 255, 255) => 777 }\n        expect(hash[Color.new(255, 255, 255)]).to eq(777)\n      end\n    end\n\n    describe \"#inspect\" do\n      subject { color.inspect }\n\n      it { expect(subject).to eq(\"rgb(1, 2, 3)[0.4][transparent]\")}\n    end\n  end\nend\n"
  },
  {
    "path": "spec/lib/gauguin/colors_clusterer_spec.rb",
    "content": "require 'spec_helper'\n\nmodule Gauguin\n  describe ColorsClusterer do\n    let(:black) { Color.new(0, 0, 0, 0.597) }\n    let(:white) { Color.new(255, 255, 255, 0.4) }\n\n    let(:clusterer) { ColorsClusterer.new }\n\n    describe \"call\" do\n      subject { clusterer.call(colors) }\n\n      context \"colors is empty\" do\n        let(:colors) { [] }\n\n        it { expect(subject).to eq({}) }\n      end\n\n      context \"colors includes similar colors\" do\n        let(:pseudo_black) { Color.new(4, 0, 0, 0.001) }\n        let(:other_pseudo_black) { Color.new(5, 0, 0, 0.001) }\n        let(:another_pseudo_black) { Color.new(6, 0, 0, 0.001) }\n\n        let(:colors) do\n          [black, white, pseudo_black, other_pseudo_black,\n           another_pseudo_black]\n        end\n\n        it \"make separate groups for them\" do\n          expect(subject).to eq({\n            white => [white],\n            black => [black, pseudo_black, other_pseudo_black,\n                      another_pseudo_black]\n          })\n        end\n\n        context do\n          let(:white) { Color.new(255, 255, 255, 0.3) }\n          let(:transparent_white) do\n            Color.new(255, 255, 255, 0.1, Image::Pixel::MAX_TRANSPARENCY)\n          end\n\n          it \"make separate groups for fully transparent colors\" do\n            colors << transparent_white\n\n            expect(subject).to eq({\n              white => [white],\n              transparent_white => [transparent_white],\n              black => [black, pseudo_black, other_pseudo_black,\n                        another_pseudo_black]\n            })\n          end\n        end\n\n        it \"updates percentage of leader of each group\" do\n          subject\n          expect(white.percentage).to eq(0.4)\n          expect(black.percentage).to eq(0.6)\n        end\n\n        context \"there is color with bigger percentage\n                  than pivot in the group\" do\n          before do\n            black.percentage = 0.001\n            other_pseudo_black.percentage = 0.597\n          end\n\n          it \"chooses it as pivot\" do\n            expect(subject).to eq({\n              white => [white],\n              other_pseudo_black => [black, pseudo_black,\n                                     other_pseudo_black,\n                                     another_pseudo_black]\n            })\n          end\n\n          context \"pivots are similar\" do\n            before do\n              other_pseudo_black.red = 30\n              another_pseudo_black.red = 60\n            end\n\n            it \"merge their groups\" do\n              expect(subject).to eq({\n                white => [white],\n                other_pseudo_black => [black, pseudo_black,\n                                      other_pseudo_black,\n                                      another_pseudo_black]\n              })\n            end\n          end\n        end\n      end\n\n      context \"colors includes different colors\" do\n        let(:colors) do\n          [black, white]\n        end\n\n        before do\n          expect(white).to receive(:similar?).\n            with(black).and_return(false)\n        end\n\n        it \"make separate groups for them\" do\n          expect(subject).to eq({\n            black => [black],\n            white => [white]\n          })\n        end\n      end\n    end\n\n    describe \"#clusters\" do\n      let(:red) { Color.new(255, 0, 0, 0.1) }\n      let(:colors) { [black, red, white] }\n\n      subject { clusterer.clusters(colors) }\n\n      configure(:max_colors_count, 2)\n\n      before do\n        expect(clusterer).to receive(:call).and_return({\n          black => [black],\n          red => [red],\n          white => [white]\n        })\n      end\n\n      it \"returns max_colors_count most common colors\" do\n        expect(subject).to eq({\n          white => [white],\n          black => [black]\n        })\n      end\n    end\n\n    describe \"#reversed_clusters\" do\n      let(:gray) { Color.new(0, 0, 10, 0.4) }\n      let(:clusters) do\n        {\n          white => [white],\n          black => [black, gray]\n        }\n      end\n\n      subject { clusterer.reversed_clusters(clusters) }\n\n      it \"returns reversed clusters\" do\n        expect(subject).to eq({\n          white => white,\n          black => black,\n          gray => black\n        })\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "spec/lib/gauguin/colors_limiter_spec.rb",
    "content": "require 'spec_helper'\n\nmodule Gauguin\n  describe ColorsLimiter do\n    describe \"#limit\" do\n      let(:limiter) { ColorsLimiter.new }\n      let(:colors) { [black, red, white] }\n      let(:white) { Color.new(255, 255, 255, 0.01) }\n      let(:red) { Color.new(255, 0, 0, 0.02) }\n      let(:black) { Color.new(0, 0, 0, 0.97) }\n\n      subject { limiter.call(colors) }\n\n      it \"returns all colors\" do\n        expect(subject).to eq([black, red, white])\n      end\n\n      context \"colors count is greater than colors_limit\" do\n        configure(:colors_limit, 2)\n\n        it \"reduces colors to colors_limit\" do\n          expect(subject).to eq([black, red])\n        end\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "spec/lib/gauguin/colors_retriever_spec.rb",
    "content": "require 'spec_helper'\n\nmodule Gauguin\n  describe ColorsRetriever do\n    let(:retriever) { ColorsRetriever.new(image) }\n    let(:image) do\n      fake = FakeImage.new\n\n      fake.magic_black_pixel = magic_black_pixel\n      fake.magic_white_pixel = magic_white_pixel\n      fake.magic_red_pixel = magic_red_pixel\n      fake.magic_red_little_transparent_pixel = magic_red_little_transparent_pixel\n\n      fake.pixels_repository = {\n        magic_white_pixel => FakeImage::Pixel.new(magic_white_pixel),\n        magic_red_pixel => FakeImage::Pixel.new(magic_red_pixel),\n        magic_black_pixel => FakeImage::Pixel.new(magic_black_pixel),\n        magic_red_little_transparent_pixel => FakeImage::Pixel.new(\n          magic_red_little_transparent_pixel)\n      }\n\n      fake.color_histogram = {\n        magic_white_pixel => 20,\n        magic_black_pixel => 30,\n        magic_red_pixel => 10\n      }\n\n      fake.rows = 10\n      fake.columns = 10\n\n      fake\n    end\n\n    def magic_pixel(rgb, opacity)\n      double(rgb: rgb, opacity: opacity)\n    end\n\n    let(:magic_black_pixel) { magic_pixel([0, 0, 0], 0) }\n    let(:magic_white_pixel) { magic_pixel([255, 255, 255], 0) }\n    let(:magic_red_pixel) { magic_pixel([255, 0, 0], 0) }\n    let(:magic_red_little_transparent_pixel) { magic_pixel([255, 0, 0], 50) }\n\n    describe \"#colors\" do\n      subject { retriever.colors.sort_by(&:percentage) }\n\n      it \"returns array with colors with percentages\" do\n        expect(subject).to eq([\n          Color.new(255, 0, 0, 0.1),\n          Color.new(255, 255, 255, 0.2),\n          Color.new(0, 0, 0, 0.3)\n        ])\n      end\n\n      context \"histogram contains different magic pixels\n        for the same color with different opacity\" do\n        before do\n          image.color_histogram[magic_red_little_transparent_pixel] = 40\n        end\n\n        it \"sums percentage\" do\n          expect(subject).to eq([\n            Color.new(255, 255, 255, 0.2),\n            Color.new(0, 0, 0, 0.3),\n            Color.new(255, 0, 0, 0.5)\n          ])\n        end\n\n        context \"fully transparent colors\" do\n          let(:magic_red_little_transparent_pixel) do\n            magic_pixel([255, 0, 0], Image::Pixel::MAX_TRANSPARENCY)\n          end\n\n          it \"should be treated separately\" do\n            expect(subject).to eq([\n              Color.new(255, 0, 0, 0.1),\n              Color.new(255, 255, 255, 0.2),\n              Color.new(0, 0, 0, 0.3),\n              Color.new(255, 0, 0, 0.4, true)\n            ])\n          end\n        end\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "spec/lib/gauguin/image_recolorer_spec.rb",
    "content": "require 'spec_helper'\n\nmodule Gauguin\n  describe ImageRecolorer do\n    describe \"#recolor\" do\n      let(:image) do\n        fake = FakeImage.new\n\n        fake.pixels = pixels\n        fake.rows = pixels.count\n        fake.columns = pixels.first.count\n        fake.colors_to_pixels = {\n          white.to_s => white_pixel,\n          red.to_s => red_pixel,\n          black.to_s => black_pixel\n        }\n\n        fake\n      end\n      let(:pixels) do\n        [\n          [black_pixel, white_pixel, white_pixel],\n          [black_pixel, black_pixel, white_pixel],\n          [black_pixel, black_pixel, black_pixel]\n        ]\n      end\n      let(:image_recolorer) { ImageRecolorer.new(image) }\n      let(:white_pixel) do\n        double('white', to_rgb: [255, 255, 255], transparent?: false)\n      end\n      let(:black_pixel) do\n        double('black', to_rgb: [0, 0, 0], transparent?: false)\n      end\n      let(:red_pixel) do\n        double('red', to_rgb: [255, 0, 0], transparent?: false)\n      end\n      let(:white) { Color.new(255, 255, 255) }\n      let(:black) { Color.new(0, 0, 0) }\n      let(:red) { Color.new(255, 0, 0) }\n      let(:new_colors) do\n        {\n          black => white,\n          white => black\n        }\n      end\n\n      subject { image_recolorer.recolor(new_colors) }\n\n      before do\n        allow(Image).to receive(:blank).and_return(image)\n      end\n\n      it \"recolors image based on new_colors\" do\n        expect(subject.pixels).to eq([\n          [white_pixel, black_pixel, black_pixel],\n          [white_pixel, white_pixel, black_pixel],\n          [white_pixel, white_pixel, white_pixel]\n        ])\n      end\n\n      context \"transparent pixel\" do\n        let(:black_pixel) do\n          double('black', to_rgb: [0, 0, 0], transparent?: true)\n        end\n\n        it \"stays the same\" do\n          expect(subject.pixels).to eq([\n            [black_pixel, black_pixel, black_pixel],\n            [black_pixel, black_pixel, black_pixel],\n            [black_pixel, black_pixel, black_pixel]\n          ])\n        end\n      end\n\n      context \"color not present in new_colors\" do\n        let(:pixels) do\n          [\n            [red_pixel, white_pixel, white_pixel],\n            [red_pixel, red_pixel, white_pixel],\n            [red_pixel, red_pixel, red_pixel]\n          ]\n        end\n\n        it \"stays the same\" do\n          expect(subject.pixels).to eq([\n            [red_pixel, black_pixel, black_pixel],\n            [red_pixel, red_pixel, black_pixel],\n            [red_pixel, red_pixel, red_pixel]\n          ])\n        end\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "spec/lib/gauguin/image_repository_spec.rb",
    "content": "require 'spec_helper'\n\nmodule Gauguin\n  describe ImageRepository do\n    let(:repository) { ImageRepository.new }\n    let(:path) { \"path\" }\n\n    describe \"#get\" do\n      it \"returns image\" do\n        expect(Gauguin::Image).to receive(:new).with(path)\n        repository.get(path)\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "spec/lib/gauguin/image_spec.rb",
    "content": "require 'spec_helper'\n\nmodule Gauguin\n  describe Image do\n    let(:path) do\n      File.join(\"spec\", \"support\", \"pictures\", \"gray_and_black.png\")\n    end\n\n    let(:image) { Image.new(path) }\n    let(:magic_pixel) { double }\n\n    describe \"initialize\" do\n      context \"path given\" do\n        subject { Image.new(path) }\n\n        it \"returns Image with magick image present\" do\n          expect(subject.image).not_to be nil\n        end\n      end\n\n      context \"empty constructor\" do\n        subject { Image.new }\n\n        it \"returns Image without magick image\" do\n          expect(subject.image).to be nil\n        end\n      end\n    end\n\n    describe \".blank\" do\n      let(:rows) { 10 }\n      let(:columns) { 20 }\n\n\n      it \"returns blank image with transparent background\" do\n        blank_image = Image.blank(rows, columns)\n\n        pixels = columns.times.map do |column|\n          rows.times.map do |row|\n            blank_image.pixel_color(column, row)\n          end\n        end.flatten\n\n        expect(pixels.all? { |p| p.transparent? }).to be true\n      end\n    end\n\n    describe \"#pixel\" do\n      it \"returns new Image::Pixel\" do\n        expect(Image::Pixel).to receive(:new)\n        image.pixel(magic_pixel)\n      end\n    end\n\n    describe \"#pixel_color\" do\n      subject { image.pixel_color(0, 0) }\n\n      it \"returns Image::Pixel for given row and column\" do\n        expect(subject.to_rgb).to eq([204, 204, 204])\n      end\n    end\n\n    describe Image::Pixel do\n      let(:pixel) { Image::Pixel.new(magic_pixel) }\n\n      describe \"#transparent?\" do\n        let(:magic_pixel) { double(opacity: opacity) }\n        let(:opacity) { 0 }\n\n        subject { pixel.transparent? }\n\n        it { expect(subject).to be false }\n\n        context \"opacity equals MAX_TRANSPARENCY\" do\n          let(:opacity) { Image::Pixel::MAX_TRANSPARENCY }\n\n          it { expect(subject).to be true }\n        end\n      end\n\n      describe \"#to_rgb\" do\n        let(:magic_pixel) { double(red: 65535, green: 0, blue: 0) }\n\n        subject { pixel.to_rgb }\n\n        it { expect(subject).to eq([255, 0, 0]) }\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "spec/lib/gauguin/noise_reducer_spec.rb",
    "content": "require 'spec_helper'\n\nmodule Gauguin\n  describe NoiseReducer do\n    let(:reducer) { NoiseReducer.new }\n\n    describe \"#reduce\" do\n      subject { reducer.call(colors).keys }\n\n      let(:white) { Color.new(255, 255, 255, 0.01) }\n      let(:red) { Color.new(255, 0, 0, 0.02) }\n      let(:black) { Color.new(0, 0, 0, 0.97) }\n\n      let(:colors) do\n        {\n          black => [black],\n          red => [red],\n          white => [white]\n        }\n      end\n\n      configure(:min_percentage_sum, 0.96)\n\n      it \"returns only relevant colors\" do\n        expect(subject).to eq([black])\n      end\n\n      context \"no sum greater than min_percentage_sum\" do\n        let(:white) { Color.new(255, 255, 255, 0.02) }\n        let(:red) { Color.new(255, 0, 0, 0.01) }\n        let(:black) { Color.new(0, 0, 0, 0.90) }\n\n        it \"returns all colors\" do\n          expect(subject).to eq([black, red, white])\n        end\n      end\n\n      context \"transparent color\" do\n        configure(:min_percentage_sum, 0.98)\n\n        before do\n          white.transparent = true\n        end\n\n        it \"returns all colors except white\" do\n          expect(subject).to eq([black, red])\n        end\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "spec/lib/gauguin/painting_spec.rb",
    "content": "require 'spec_helper'\n\nmodule Gauguin\n  describe Painting do\n    let(:colors) { [] }\n\n    let(:image_repository) { double(get: double('image')) }\n    let(:colors_retriever) { double }\n    let(:colors_limiter) { double }\n    let(:noise_reducer) { double }\n    let(:colors_clusterer) { double }\n    let(:image_recolorer) { double }\n\n    let(:clusters) { {} }\n\n    let(:painting) do\n      Painting.new(\"path\", image_repository, colors_retriever,\n                   colors_limiter, noise_reducer,\n                   colors_clusterer, image_recolorer)\n    end\n\n    describe \"#palette\" do\n      it \"returns hash with main colors of the image\" do\n        expect(colors_retriever).to receive(:colors).\n          and_return(colors)\n        expect(colors_limiter).to receive(:call).with(colors).\n          and_return(colors)\n        expect(colors_clusterer).to receive(:clusters).with(colors).\n          and_return(clusters)\n        expect(noise_reducer).to receive(:call).with(clusters).\n          and_return(colors)\n\n        painting.palette\n      end\n    end\n\n    describe \"#recolor\" do\n      let(:palette) { {} }\n      let(:path) { 'path' }\n      let(:image) { double(write: nil) }\n      let(:new_colors) { {} }\n\n      it \"recolors and writes the image to given path\" do\n        expect(colors_clusterer).to receive(:reversed_clusters).\n          with(palette).and_return(new_colors)\n        expect(image_recolorer).to receive(:recolor).\n          with(new_colors).and_return(image)\n        expect(image).to receive(:write).with(path)\n\n        painting.recolor(palette, path)\n      end\n    end\n  end\nend\n\n"
  },
  {
    "path": "spec/lib/gauguin/palette_serializer_spec.rb",
    "content": "require 'spec_helper'\n\nmodule Gauguin\n  describe PaletteSerializer do\n    let(:palette) do\n      {\n        Color.new(255, 255, 255, 0.7, true) => [Color.new(255, 0, 0, 0.7, true)]\n      }\n    end\n\n    it \"serializes palette\" do\n      dumped = PaletteSerializer.dump(palette)\n      loaded = PaletteSerializer.load(dumped)\n\n      key = loaded.keys.first\n      value = loaded.values.first.first\n\n      expect(key.class).to eq(Color)\n      expect(value.class).to eq(Color)\n      expect(key.to_a).to eq([255, 255, 255, 0.7, true])\n      expect(value.to_a).to eq([255, 0, 0, 0.7, true])\n    end\n  end\nend\n"
  },
  {
    "path": "spec/spec_helper.rb",
    "content": "if ENV['CODECLIMATE_REPO_TOKEN']\n  require \"codeclimate-test-reporter\"\n  CodeClimate::TestReporter.start\nelse\n  require 'simplecov'\n  SimpleCov.start\nend\n\nrequire 'bundler/setup'\nrequire './lib/gauguin'\nrequire 'pry'\n\nBundler.setup\n\nRSpec.configure do |config|\nend\n\ndef configure(config_option, value)\n  old_value = Gauguin.configuration.send(config_option)\n\n  before do\n    Gauguin.configuration.send(\"#{config_option}=\", value)\n  end\n\n  after do\n    Gauguin.configuration.send(\"#{config_option}=\", old_value)\n  end\nend\n\nclass FakeImage\n  attr_accessor :magic_black_pixel, :magic_red_pixel,\n    :magic_white_pixel, :magic_red_little_transparent_pixel,\n    :pixels_repository, :color_histogram, :rows, :columns,\n    :pixels, :colors_to_pixels\n\n  def pixel(magic_pixel)\n    pixels_repository[magic_pixel]\n  end\n\n  def pixel_color(row, column, new_color = nil)\n    if new_color\n      new_pixel = self.colors_to_pixels[new_color]\n      pixels[row][column] = new_pixel\n    end\n    pixels[row][column]\n  end\n\n  class Pixel < Gauguin::Image::Pixel\n    attr_accessor :magic_pixel\n\n    def initialize(magic_pixel)\n      self.magic_pixel = magic_pixel\n    end\n\n    def to_rgb\n      magic_pixel.rgb\n    end\n  end\nend\n\n"
  }
]