15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)/*
25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *
45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * This library is free software; you can redistribute it and/or
55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * modify it under the terms of the GNU Library General Public
65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * License as published by the Free Software Foundation; either
75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * version 2 of the License, or (at your option) any later version.
85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *
95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * This library is distributed in the hope that it will be useful,
105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * but WITHOUT ANY WARRANTY; without even the implied warranty of
115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
125c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu * Library General Public License for more details.
135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *
14116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch * You should have received a copy of the GNU Library General Public License
155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * along with this library; see the file COPYING.LIB.  If not, write to
165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * Boston, MA 02110-1301, USA.
185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) */
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "config.h"
215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "core/svg/ColorDistance.h"
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "platform/graphics/Color.h"
245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace blink {
265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)Color ColorDistance::addColors(const Color& first, const Color& second)
285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles){
295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return Color(first.red() + second.red(), first.green() + second.green(), first.blue() + second.blue());
305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)float ColorDistance::distance(const Color& fromColor, const Color& toColor)
335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles){
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    int redDiff = toColor.red() - fromColor.red();
355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    int greenDiff = toColor.green() - fromColor.green();
365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    int blueDiff = toColor.blue() - fromColor.blue();
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // This is just a simple distance calculation, not respecting color spaces
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return sqrtf(redDiff * redDiff + blueDiff * blueDiff + greenDiff * greenDiff);
405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)