/* This file is part of Mapnik (c++ mapping toolkit) * Copyright (C) 2005 Artem Pavlenko * * Mapnik 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 any later version. * * This program 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. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ //$Id$ #include #ifndef COLORCUBE_HPP #define COLORCUBE_HPP namespace mapnik { template struct color_cube { const static unsigned maxcolors=rLevel * gLevel * bLevel + 32; static unsigned cube[maxcolors]; static bool initialized; static unsigned rDiv; static unsigned gDiv; static unsigned bDiv; static unsigned color(unsigned red,unsigned green,unsigned blue) { if (!initialized) init(); unsigned index=rgb_level_index(red/rDiv,green/gDiv,blue/bDiv); return cube[index]; } private: static unsigned rgb_level_index(unsigned red,unsigned green,unsigned blue) { return (red * gLevel * bLevel + green * bLevel + blue); } static void init() { unsigned red,green,blue; unsigned count=0; for (int r=0;r //unsigned color_cube::cube[color_cube::maxcolors]; template unsigned color_cube::rDiv=52; template unsigned color_cube::gDiv=52; template unsigned color_cube::bDiv=52; template bool color_cube::initialized=false; } #endif