X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fsynfig%2Fpalette.cpp;h=16742a41817129cb4256540946c4128f791b2171;hb=9459638ad6797b8139f1e9f0715c96076dbf0890;hp=4ff3a660c5beeea3fa0c1453509c48e7646a92f8;hpb=e3acc0b267b14fda5db3c7bbb2f218b993ef84b3;p=synfig.git diff --git a/synfig-core/trunk/src/synfig/palette.cpp b/synfig-core/trunk/src/synfig/palette.cpp index 4ff3a66..16742a4 100644 --- a/synfig-core/trunk/src/synfig/palette.cpp +++ b/synfig-core/trunk/src/synfig/palette.cpp @@ -1,20 +1,21 @@ -/* === S I N F G =========================================================== */ -/*! \file template.cpp +/* === S Y N F I G ========================================================= */ +/*! \file palette.cpp ** \brief Template File ** -** $Id: palette.cpp,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $ +** $Id$ ** ** \legal -** Copyright (c) 2002 Robert B. Quattlebaum Jr. +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley ** -** This software and associated documentation -** are CONFIDENTIAL and PROPRIETARY property of -** the above-mentioned copyright holder. +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. ** -** You may not copy, print, publish, or in any -** other way distribute this software without -** a prior written agreement with -** the copyright holder. +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. ** \endlegal */ /* ========================================================================= */ @@ -40,11 +41,11 @@ using namespace std; using namespace etl; -using namespace sinfg; +using namespace synfig; /* === M A C R O S ========================================================= */ -#define PALETTE_FILE_COOKIE "SINFGPAL1.0" +#define PALETTE_FILE_COOKIE "SYNFIGPAL1.0" /* === G L O B A L S ======================================================= */ @@ -86,14 +87,15 @@ PaletteItem::add(const Color& x,int xweight) Palette::Palette(const Surface& surface, int max_colors): name_(_("Surface Palette")) -{ +{ max_colors-=2; - for(int y=0;yadd(color); continue; } - + /*if(size()>=max_colors) { iterator iterlight(find_light()); @@ -123,9 +125,44 @@ Palette::Palette(const Surface& surface, int max_colors): find_closest(light.color)->add(light.color,light.weight); } */ - + push_back(color); - continue; + continue; + } + +/* + + max_colors-=2; + for(int y=0;yadd(color); + continue; + } + + + push_back(color); + continue; } sort(rbegin(),rend()); @@ -138,6 +175,7 @@ Palette::Palette(const Surface& surface, int max_colors): pop_back(); find_closest(item.color)->add(item.color,item.weight); } +*/ push_back(Color::black()); push_back(Color::white()); @@ -165,7 +203,7 @@ Palette::find_closest(const Color& color, float* dist) const float prep_y(powf(color.get_y(),2.2f)*color.get_a()); const float prep_u(color.get_u()); const float prep_v(color.get_v()); - + for(iter=begin();iter!=end();++iter) { const float diff_y(prep_y-powf(iter->color.get_y(),2.2f)*iter->color.get_a()); @@ -178,12 +216,12 @@ Palette::find_closest(const Color& color, float* dist) diff_y*diff_y*1.5f+ diff_a*diff_a+ - diff_u*diff_u+ + diff_u*diff_u+ diff_v*diff_v - + // cross product /*abs( - prep_u*iter->color.get_u()- + prep_u*iter->color.get_u()- prep_v*iter->color.get_v() )*/ ); @@ -195,7 +233,7 @@ Palette::find_closest(const Color& color, float* dist) } if(dist) *dist=best_dist; - + return best_match; } @@ -206,13 +244,13 @@ Palette::find_heavy() iterator iter; iterator best_match(begin()); - + for(iter=begin();iter!=end();++iter) { if(iter->weight>best_match->weight) best_match=iter; } - + return best_match; } @@ -222,13 +260,13 @@ Palette::find_light() iterator iter; iterator best_match(begin()); - + for(iter=begin();iter!=end();++iter) { if(iter->weightweight) best_match=iter; } - + return best_match; } @@ -251,17 +289,17 @@ Palette::grayscale(int steps) } void -Palette::save_to_file(const sinfg::String& filename)const +Palette::save_to_file(const synfig::String& filename)const { const_iterator iter; std::ofstream file(filename.c_str()); - + if(!file) throw strprintf(_("Unable to open %s for write"),filename.c_str()); - + file<name<color.get_g()<color.get_b()<color.get_a()<